From 777438fd940e74fe87f20887fddabd8d41e3f98a Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Sat, 6 Apr 2024 21:23:26 -0500 Subject: [PATCH] rename props.brew.uiItems to ...accountDetails and destructure props at start of account page component. `accountDetails` is more descriptive of what set of info is being passed through props to the account page, info which is only *then* displayed as UI items. --- client/homebrew/homebrew.jsx | 2 +- .../pages/accountPage/accountPage.jsx | 26 +++++++++++-------- server/app.js | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index a08a39ea0..8c82f33e7 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -76,7 +76,7 @@ const Homebrew = createClass({ } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 72d60a741..e65736a24 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -8,16 +8,20 @@ const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); let SAVEKEY = ''; const AccountPage = (props)=>{ + // destructure props + const { accountDetails, brew } = props; + + // State for the save location const [saveLocation, setSaveLocation] = React.useState(''); // initialize save location from local storage based on user id React.useEffect(()=>{ - if(!saveLocation && props.uiItems.username) { - SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${props.uiItems.username}`; + if(!saveLocation && accountDetails.username) { + SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${accountDetails.username}`; // if no SAVEKEY in local storage, default save location to Google Drive. let saveLocation = window.localStorage.getItem(SAVEKEY); - saveLocation = saveLocation ?? (props.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); + saveLocation = saveLocation ?? (accountDetails.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); makeActive(saveLocation); } }, []); @@ -51,19 +55,19 @@ const AccountPage = (props)=>{ <>

Account Information

-

Username: {props.uiItems.username || 'No user currently logged in'}

-

Last Login: {moment(props.uiItems.issued).format('dddd, MMMM Do YYYY, h:mm:ss a ZZ') || '-'}

+

Username: {accountDetails.username || 'No user currently logged in'}

+

Last Login: {moment(accountDetails.issued).format('dddd, MMMM Do YYYY, h:mm:ss a ZZ') || '-'}

Homebrewery Information

-

Brews on Homebrewery: {props.uiItems.mongoCount}

+

Brews on Homebrewery: {accountDetails.mongoCount}

Google Information

-

Linked to Google: {props.uiItems.googleId ? 'YES' : 'NO'}

- {props.uiItems.googleId && ( +

Linked to Google: {accountDetails.googleId ? 'YES' : 'NO'}

+ {accountDetails.googleId && (

- Brews on Google Drive: {props.uiItems.googleCount ?? ( + Brews on Google Drive: {accountDetails.googleCount ?? ( <> Unable to retrieve files - follow these steps to renew your Google credentials. @@ -74,7 +78,7 @@ const AccountPage = (props)=>{

Default Save Location

{renderButton('Homebrewery', 'HOMEBREWERY')} - {renderButton('Google Drive', 'GOOGLE-DRIVE', props.uiItems.googleId)} + {renderButton('Google Drive', 'GOOGLE-DRIVE', accountDetails.googleId)}
); @@ -82,7 +86,7 @@ const AccountPage = (props)=>{ // return the account page inside the base layout wrapper (with navbar etc). return ( - + {renderAccountPage()} ); }; diff --git a/server/app.js b/server/app.js index 4c72b4924..c8fec4bc4 100644 --- a/server/app.js +++ b/server/app.js @@ -372,7 +372,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ console.log(err); }); - data.uiItems = { + data.accountDetails = { username : req.account.username, issued : req.account.issued, googleId : Boolean(req.account.googleId),