diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index c796b9d22..88a347121 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -1,5 +1,4 @@ const React = require('react'); -const createClass = require('create-react-class'); const moment = require('moment'); const UIPage = require('../basePages/uiPage/uiPage.jsx'); @@ -8,74 +7,76 @@ const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); let SAVEKEY = ''; -const AccountPage = createClass({ - displayName : 'AccountPage', - getDefaultProps : function() { - return { - brew : {}, - uiItems : {} - }; - }, - getInitialState : function() { - return { - uiItems : this.props.uiItems - }; - }, - componentDidMount : function(){ - if(!this.state.saveLocation && this.props.uiItems.username) { - SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${this.props.uiItems.username}`; - let saveLocation = window.localStorage.getItem(SAVEKEY); - saveLocation = saveLocation ?? (this.state.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); - this.makeActive(saveLocation); +const AccountPage = (props)=>{ + const [saveLocation, setSaveLocation] = React.useState(''); + + React.useEffect(()=>{ + if(!saveLocation && props.uiItems.username) { + SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${props.uiItems.username}`; + let saveLocation = window.localStorage.getItem(SAVEKEY); + saveLocation = saveLocation ?? (props.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); + makeActive(saveLocation); } - }, + }, []); - makeActive : function(newSelection){ - if(this.state.saveLocation == newSelection) return; + const makeActive = (newSelection)=>{ + if(saveLocation === newSelection) return; window.localStorage.setItem(SAVEKEY, newSelection); - this.setState({ - saveLocation : newSelection - }); - }, + setSaveLocation(newSelection); + }; - renderButton : function(name, key, shouldRender=true){ - if(!shouldRender) return; - return ; - }, + const renderButton = (name, key, shouldRender = true)=>{ + if(!shouldRender) return null; + return ( + + ); + }; - renderUiItems : function() { - return <> -
-

Account Information

-

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

-

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

-
-
-

Homebrewery Information

-

Brews on Homebrewery: {this.props.uiItems.mongoCount}

-
-
-

Google Information

-

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

- {this.props.uiItems.googleId && -

- Brews on Google Drive: {this.props.uiItems.googleCount ?? <>Unable to retrieve files - follow these steps to renew your Google credentials.} -

- } -
-
-

Default Save Location

- {this.renderButton('Homebrewery', 'HOMEBREWERY')} - {this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.googleId)} -
- ; - }, + const renderUiItems = ()=>{ + return ( + <> +
+

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') || '-'}

+
+
+

Homebrewery Information

+

Brews on Homebrewery: {props.uiItems.mongoCount}

+
+
+

Google Information

+

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

+ {props.uiItems.googleId && ( +

+ Brews on Google Drive: {props.uiItems.googleCount ?? ( + <> + Unable to retrieve files - follow these steps to renew your Google credentials. + + )} +

+ )} +
+
+

Default Save Location

+ {renderButton('Homebrewery', 'HOMEBREWERY')} + {renderButton('Google Drive', 'GOOGLE-DRIVE', props.uiItems.googleId)} +
+ + ); + }; - render : function(){ - return - {this.renderUiItems()} - ; - } -}); + return ( + + {renderUiItems()} + ); +}; module.exports = AccountPage;