0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 18:42:40 +00:00

Merge branch 'master' into dependabot/npm_and_yarn/mongoose-8.3.1

This commit is contained in:
Trevor Buckner
2024-04-09 11:39:03 -04:00
committed by GitHub
3 changed files with 70 additions and 90 deletions

View File

@@ -76,7 +76,7 @@ const Homebrew = createClass({
<Route path='/print' element={<WithRoute el={PrintPage} />} /> <Route path='/print' element={<WithRoute el={PrintPage} />} />
<Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} /> <Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} /> <Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} uiItems={this.props.brew.uiItems} />} /> <Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} accountDetails={this.props.brew.accountDetails} />} />
<Route path='/legacy' element={<WithRoute el={HomePage} brew={this.props.brew} />} /> <Route path='/legacy' element={<WithRoute el={HomePage} brew={this.props.brew} />} />
<Route path='/error' element={<WithRoute el={ErrorPage} brew={this.props.brew} />} /> <Route path='/error' element={<WithRoute el={ErrorPage} brew={this.props.brew} />} />
<Route path='/' element={<WithRoute el={HomePage} brew={this.props.brew} />} /> <Route path='/' element={<WithRoute el={HomePage} brew={this.props.brew} />} />

View File

@@ -1,102 +1,82 @@
const React = require('react'); const React = require('react');
const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames');
const moment = require('moment'); const moment = require('moment');
const UIPage = require('../basePages/uiPage/uiPage.jsx'); const UIPage = require('../basePages/uiPage/uiPage.jsx');
const Nav = require('naturalcrit/nav/nav.jsx');
const Navbar = require('../../navbar/navbar.jsx');
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
const Account = require('../../navbar/account.navitem.jsx');
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
const HelpNavItem = require('../../navbar/help.navitem.jsx');
const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx');
let SAVEKEY = ''; let SAVEKEY = '';
const AccountPage = createClass({ const AccountPage = (props)=>{
displayName : 'AccountPage', // destructure props and set state for save location
getDefaultProps : function() { const { accountDetails, brew } = props;
return { const [saveLocation, setSaveLocation] = React.useState('');
brew : {},
uiItems : {} // initialize save location from local storage based on user id
}; React.useEffect(()=>{
}, if(!saveLocation && accountDetails.username) {
getInitialState : function() { SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${accountDetails.username}`;
return { // if no SAVEKEY in local storage, default save location to Google Drive if user has Google account.
uiItems : this.props.uiItems let saveLocation = window.localStorage.getItem(SAVEKEY);
}; saveLocation = saveLocation ?? (accountDetails.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY');
}, setActiveSaveLocation(saveLocation);
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);
} }
}, }, []);
makeActive : function(newSelection){ const setActiveSaveLocation = (newSelection)=>{
if(this.state.saveLocation == newSelection) return; if(saveLocation === newSelection) return;
window.localStorage.setItem(SAVEKEY, newSelection); window.localStorage.setItem(SAVEKEY, newSelection);
this.setState({ setSaveLocation(newSelection);
saveLocation : newSelection };
});
},
renderButton : function(name, key, shouldRender=true){ // todo: should this be a set of radio buttons (well styled) since it's either/or choice?
if(!shouldRender) return; const renderSaveLocationButton = (name, key, shouldRender = true)=>{
return <button className={this.state.saveLocation==key ? 'active' : ''} onClick={()=>{this.makeActive(key);}}>{name}</button>; if(!shouldRender) return null;
}, return (
<button className={saveLocation === key ? 'active' : ''} onClick={()=>{setActiveSaveLocation(key);}}>
{name}
</button>
);
};
renderNavItems : function() { // render the entirety of the account page content
return <Navbar> const renderAccountPage = ()=>{
<Nav.section> return (
<NewBrew /> <>
<HelpNavItem /> <div className='dataGroup'>
<RecentNavItem /> <h1>Account Information <i className='fas fa-user'></i></h1>
<Account /> <p><strong>Username: </strong>{accountDetails.username || 'No user currently logged in'}</p>
</Nav.section> <p><strong>Last Login: </strong>{moment(accountDetails.issued).format('dddd, MMMM Do YYYY, h:mm:ss a ZZ') || '-'}</p>
</Navbar>; </div>
}, <div className='dataGroup'>
<h3>Homebrewery Information <NaturalCritIcon /></h3>
<p><strong>Brews on Homebrewery: </strong>{accountDetails.mongoCount}</p>
</div>
<div className='dataGroup'>
<h3>Google Information <i className='fab fa-google-drive'></i></h3>
<p><strong>Linked to Google: </strong>{accountDetails.googleId ? 'YES' : 'NO'}</p>
{accountDetails.googleId && (
<p>
<strong>Brews on Google Drive: </strong>{accountDetails.googleCount ?? (
<>
Unable to retrieve files - <a href='https://github.com/naturalcrit/homebrewery/discussions/1580'>follow these steps to renew your Google credentials.</a>
</>
)}
</p>
)}
</div>
<div className='dataGroup'>
<h4>Default Save Location</h4>
{renderSaveLocationButton('Homebrewery', 'HOMEBREWERY')}
{renderSaveLocationButton('Google Drive', 'GOOGLE-DRIVE', accountDetails.googleId)}
</div>
</>
);
};
renderUiItems : function() { // return the account page inside the base layout wrapper (with navbar etc).
return <> return (
<div className='dataGroup'> <UIPage brew={brew}>
<h1>Account Information <i className='fas fa-user'></i></h1> {renderAccountPage()}
<p><strong>Username: </strong> {this.props.uiItems.username || 'No user currently logged in'}</p> </UIPage>);
<p><strong>Last Login: </strong> {moment(this.props.uiItems.issued).format('dddd, MMMM Do YYYY, h:mm:ss a ZZ') || '-'}</p> };
</div>
<div className='dataGroup'>
<h3>Homebrewery Information <NaturalCritIcon /></h3>
<p><strong>Brews on Homebrewery: </strong> {this.props.uiItems.mongoCount}</p>
</div>
<div className='dataGroup'>
<h3>Google Information <i className='fab fa-google-drive'></i></h3>
<p><strong>Linked to Google: </strong> {this.props.uiItems.googleId ? 'YES' : 'NO'}</p>
{this.props.uiItems.googleId &&
<p>
<strong>Brews on Google Drive: </strong> {this.props.uiItems.googleCount ?? <>Unable to retrieve files - <a href='https://github.com/naturalcrit/homebrewery/discussions/1580'>follow these steps to renew your Google credentials.</a></>}
</p>
}
</div>
<div className='dataGroup'>
<h4>Default Save Location</h4>
{this.renderButton('Homebrewery', 'HOMEBREWERY')}
{this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.googleId)}
</div>
</>;
},
render : function(){
return <UIPage brew={this.props.brew}>
{this.renderUiItems()}
</UIPage>;
}
});
module.exports = AccountPage; module.exports = AccountPage;

View File

@@ -372,7 +372,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
console.log(err); console.log(err);
}); });
data.uiItems = { data.accountDetails = {
username : req.account.username, username : req.account.username,
issued : req.account.issued, issued : req.account.issued,
googleId : Boolean(req.account.googleId), googleId : Boolean(req.account.googleId),