From 7942f1caedbf38c50f49e21e2c0e77bb619a3ff6 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 19:36:14 +1200 Subject: [PATCH 1/8] Initial functionality pass --- .../pages/accountPage/accountPage.jsx | 34 +++++++++++++++++++ .../pages/basePages/uiPage/uiPage.less | 17 ++++++++++ client/homebrew/pages/newPage/newPage.jsx | 9 +++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 77f246a8b..371219240 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -16,6 +16,8 @@ const HelpNavItem = require('../../navbar/help.navitem.jsx'); const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); +const saveLocationKey = 'HOMEBREWERY-DEFAULT-SAVE-LOCATION'; + const AccountPage = createClass({ displayName : 'AccountPage', getDefaultProps : function() { @@ -29,6 +31,31 @@ const AccountPage = createClass({ uiItems : this.props.uiItems }; }, + componentDidMount : function(){ + if(!this.state.saveLocation) { + const saveLocation = window.localStorage.getItem(saveLocationKey) || ''; + if(saveLocation == '') { + // TO DO: Implement logic to determine the appropriate location given current state + console.log(this.state.uiItems); + }; + this.setState({ + saveLocation : saveLocation + }); + } + }, + + makeActive : function(newSelection){ + if(this.state.saveLocation == newSelection) return; + window.localStorage.setItem(saveLocationKey, newSelection); + this.setState({ + saveLocation : newSelection + }); + }, + + renderButton : function(name, key, condition=true){ + if(!condition) return; + return ; + }, renderNavItems : function() { return @@ -48,6 +75,13 @@ const AccountPage = createClass({

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

+
+

Default Save Location

+ {/* */} + {this.renderButton('Homebrewery', 'HOMEBREWERY')} + {/* {this.state.uiItems.googleId ? : <>} */} + {this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.username)} +

Homebrewery Information

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

diff --git a/client/homebrew/pages/basePages/uiPage/uiPage.less b/client/homebrew/pages/basePages/uiPage/uiPage.less index fc5ed583d..913c74a2e 100644 --- a/client/homebrew/pages/basePages/uiPage/uiPage.less +++ b/client/homebrew/pages/basePages/uiPage/uiPage.less @@ -16,6 +16,23 @@ margin : 5px 0px; border : 2px solid black; border-radius : 5px; + button { + background-color : transparent; + border : 1px solid black; + border-radius : 5px; + width : 125px; + color : black; + margin-right : 5px; + &.active { + background-color: #0007; + color: white; + &:before { + content: '\f00c'; + font-family: 'FONT AWESOME 5 FREE'; + margin-right: 5px; + } + } + } } h1, h2, h3, h4 { width : 100%; diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index 0f18d42be..923c4d61e 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -20,9 +20,10 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); const { DEFAULT_BREW } = require('../../../../server/brewDefaults.js'); -const BREWKEY = 'homebrewery-new'; +const BREWKEY = 'homebrewery-new'; const STYLEKEY = 'homebrewery-new-style'; -const METAKEY = 'homebrewery-new-meta'; +const METAKEY = 'homebrewery-new-meta'; +const SAVEKEY = 'HOMEBREWERY-DEFAULT-SAVE-LOCATION'; const NewPage = createClass({ @@ -54,6 +55,7 @@ const NewPage = createClass({ const brewStorage = localStorage.getItem(BREWKEY); const styleStorage = localStorage.getItem(STYLEKEY); const metaStorage = JSON.parse(localStorage.getItem(METAKEY)); + const saveStorage = localStorage.getItem(SAVEKEY); brew.text = brewStorage ?? brew.text; brew.style = styleStorage ?? brew.style; @@ -64,7 +66,8 @@ const NewPage = createClass({ brew.lang = metaStorage?.lang ?? brew.lang; this.setState({ - brew : brew + brew : brew, + saveGoogle : (saveStorage == 'GOOGLE-DRIVE' && this.state.saveGoogle) }); } From 7274d788c57d0cd2f22f9b112a79349fb9e42ca5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 19:39:07 +1200 Subject: [PATCH 2/8] Clean up comments, change to actual G-Drive check --- client/homebrew/pages/accountPage/accountPage.jsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 371219240..1d236f7ad 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -75,13 +75,6 @@ const AccountPage = createClass({

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

-
-

Default Save Location

- {/* */} - {this.renderButton('Homebrewery', 'HOMEBREWERY')} - {/* {this.state.uiItems.googleId ? : <>} */} - {this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.username)} -

Homebrewery Information

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

@@ -95,6 +88,11 @@ const AccountPage = createClass({

}
+
+

Default Save Location

+ {this.renderButton('Homebrewery', 'HOMEBREWERY')} + {this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.googleId)} +
; }, From 9e7e646296b9e73a8f09ce9385468951715713da Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 20:34:10 +1200 Subject: [PATCH 3/8] Add username to save key --- client/homebrew/pages/accountPage/accountPage.jsx | 9 +++++---- client/homebrew/pages/newPage/newPage.jsx | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 1d236f7ad..b19b0f47a 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -16,7 +16,7 @@ const HelpNavItem = require('../../navbar/help.navitem.jsx'); const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); -const saveLocationKey = 'HOMEBREWERY-DEFAULT-SAVE-LOCATION'; +let SAVEKEY = ''; const AccountPage = createClass({ displayName : 'AccountPage', @@ -32,8 +32,9 @@ const AccountPage = createClass({ }; }, componentDidMount : function(){ - if(!this.state.saveLocation) { - const saveLocation = window.localStorage.getItem(saveLocationKey) || ''; + if(!this.state.saveLocation && this.props.uiItems.username) { + SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${this.props.uiItems.username}`; + const saveLocation = window.localStorage.getItem(SAVEKEY) || ''; if(saveLocation == '') { // TO DO: Implement logic to determine the appropriate location given current state console.log(this.state.uiItems); @@ -46,7 +47,7 @@ const AccountPage = createClass({ makeActive : function(newSelection){ if(this.state.saveLocation == newSelection) return; - window.localStorage.setItem(saveLocationKey, newSelection); + window.localStorage.setItem(SAVEKEY, newSelection); this.setState({ saveLocation : newSelection }); diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index 923c4d61e..73e83960c 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -23,7 +23,7 @@ const { DEFAULT_BREW } = require('../../../../server/brewDefaults.js'); const BREWKEY = 'homebrewery-new'; const STYLEKEY = 'homebrewery-new-style'; const METAKEY = 'homebrewery-new-meta'; -const SAVEKEY = 'HOMEBREWERY-DEFAULT-SAVE-LOCATION'; +let SAVEKEY; const NewPage = createClass({ @@ -55,6 +55,8 @@ const NewPage = createClass({ const brewStorage = localStorage.getItem(BREWKEY); const styleStorage = localStorage.getItem(STYLEKEY); const metaStorage = JSON.parse(localStorage.getItem(METAKEY)); + + SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${global.account.username}`; const saveStorage = localStorage.getItem(SAVEKEY); brew.text = brewStorage ?? brew.text; From 64a361e06c2986cce99fe2c689e98a71c3f270de Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 20:36:55 +1200 Subject: [PATCH 4/8] Determine default state and set in local storage --- client/homebrew/pages/accountPage/accountPage.jsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index b19b0f47a..ad6bcdb61 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -34,10 +34,12 @@ const AccountPage = createClass({ componentDidMount : function(){ if(!this.state.saveLocation && this.props.uiItems.username) { SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${this.props.uiItems.username}`; - const saveLocation = window.localStorage.getItem(SAVEKEY) || ''; + let saveLocation = window.localStorage.getItem(SAVEKEY) || ''; if(saveLocation == '') { - // TO DO: Implement logic to determine the appropriate location given current state - console.log(this.state.uiItems); + saveLocation = 'HOMEBREWERY'; + if(this.state.uiItems.googleId) { + saveLocation = 'GOOGLE-DRIVE'; + } }; this.setState({ saveLocation : saveLocation From b869d086ea26777be1bf0f2861b50783af6e0f22 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 20:39:33 +1200 Subject: [PATCH 5/8] Add default to New Page --- client/homebrew/pages/newPage/newPage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index 73e83960c..008749b41 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -57,7 +57,7 @@ const NewPage = createClass({ const metaStorage = JSON.parse(localStorage.getItem(METAKEY)); SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${global.account.username}`; - const saveStorage = localStorage.getItem(SAVEKEY); + const saveStorage = localStorage.getItem(SAVEKEY) || 'HOMEBREWERY'; brew.text = brewStorage ?? brew.text; brew.style = styleStorage ?? brew.style; From cef7f9817634a5dabe29340070680b37131312a2 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 19 Jul 2023 20:43:49 +1200 Subject: [PATCH 6/8] Use existing makeActive function --- client/homebrew/pages/accountPage/accountPage.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index ad6bcdb61..6b5a17dfc 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -41,9 +41,7 @@ const AccountPage = createClass({ saveLocation = 'GOOGLE-DRIVE'; } }; - this.setState({ - saveLocation : saveLocation - }); + this.makeActive(saveLocation); } }, From 73832fabcc0b852a3e6bb7833b6b00bf19f13a7b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 11 Aug 2023 11:15:27 +1200 Subject: [PATCH 7/8] Update client/homebrew/pages/accountPage/accountPage.jsx Co-authored-by: Trevor Buckner --- client/homebrew/pages/accountPage/accountPage.jsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 6b5a17dfc..e14b522a4 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -34,13 +34,8 @@ const AccountPage = createClass({ 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) || ''; - if(saveLocation == '') { - saveLocation = 'HOMEBREWERY'; - if(this.state.uiItems.googleId) { - saveLocation = 'GOOGLE-DRIVE'; - } - }; + let saveLocation = window.localStorage.getItem(SAVEKEY); + saveLocation = saveLocation ?? this.state.uiItems.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'; this.makeActive(saveLocation); } }, From 7feaa51de081957dfa6730f11dafe1811cd78dbd Mon Sep 17 00:00:00 2001 From: Sean Robertson Date: Fri, 11 Aug 2023 11:56:45 +1200 Subject: [PATCH 8/8] Rename renderButton visibility control parameter --- client/homebrew/pages/accountPage/accountPage.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index e14b522a4..40c3dfdbd 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -48,8 +48,8 @@ const AccountPage = createClass({ }); }, - renderButton : function(name, key, condition=true){ - if(!condition) return; + renderButton : function(name, key, shouldRender=true){ + if(!shouldRender) return; return ; },