mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-30 06:42:45 +00:00
add code comments for each step.
This commit is contained in:
@@ -8,23 +8,29 @@ const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx');
|
|||||||
let SAVEKEY = '';
|
let SAVEKEY = '';
|
||||||
|
|
||||||
const AccountPage = (props)=>{
|
const AccountPage = (props)=>{
|
||||||
|
// State for the save location
|
||||||
const [saveLocation, setSaveLocation] = React.useState('');
|
const [saveLocation, setSaveLocation] = React.useState('');
|
||||||
|
|
||||||
|
// initialize save location from local storage based on user id
|
||||||
React.useEffect(()=>{
|
React.useEffect(()=>{
|
||||||
if(!saveLocation && props.uiItems.username) {
|
if(!saveLocation && props.uiItems.username) {
|
||||||
SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${props.uiItems.username}`;
|
SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${props.uiItems.username}`;
|
||||||
|
// if no SAVEKEY in local storage, default save location to Google Drive.
|
||||||
let saveLocation = window.localStorage.getItem(SAVEKEY);
|
let saveLocation = window.localStorage.getItem(SAVEKEY);
|
||||||
saveLocation = saveLocation ?? (props.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY');
|
saveLocation = saveLocation ?? (props.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY');
|
||||||
makeActive(saveLocation);
|
makeActive(saveLocation);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// function to set the active save location
|
||||||
const makeActive = (newSelection)=>{
|
const makeActive = (newSelection)=>{
|
||||||
if(saveLocation === newSelection) return;
|
if(saveLocation === newSelection) return;
|
||||||
window.localStorage.setItem(SAVEKEY, newSelection);
|
window.localStorage.setItem(SAVEKEY, newSelection);
|
||||||
setSaveLocation(newSelection);
|
setSaveLocation(newSelection);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// render a button for setting save locations.
|
||||||
|
// todo: should this be a set of radio buttons (well styled) since it's either/or choice?
|
||||||
const renderButton = (name, key, shouldRender = true)=>{
|
const renderButton = (name, key, shouldRender = true)=>{
|
||||||
if(!shouldRender) return null;
|
if(!shouldRender) return null;
|
||||||
return (
|
return (
|
||||||
@@ -39,6 +45,7 @@ const AccountPage = (props)=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// render the entirety of the account page content
|
||||||
const renderAccountPage = ()=>{
|
const renderAccountPage = ()=>{
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -73,6 +80,7 @@ const AccountPage = (props)=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// return the account page inside the base layout wrapper (with navbar etc).
|
||||||
return (
|
return (
|
||||||
<UIPage brew={props.brew}>
|
<UIPage brew={props.brew}>
|
||||||
{renderAccountPage()}
|
{renderAccountPage()}
|
||||||
|
|||||||
Reference in New Issue
Block a user