mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-11 22:02:41 +00:00
Merge pull request #2944 from G-Ambatte/experimentalSaveLocation
Add save location setting to local storage
This commit is contained in:
@@ -16,6 +16,8 @@ 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 = '';
|
||||||
|
|
||||||
const AccountPage = createClass({
|
const AccountPage = createClass({
|
||||||
displayName : 'AccountPage',
|
displayName : 'AccountPage',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
@@ -29,6 +31,27 @@ const AccountPage = createClass({
|
|||||||
uiItems : this.props.uiItems
|
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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
makeActive : function(newSelection){
|
||||||
|
if(this.state.saveLocation == newSelection) return;
|
||||||
|
window.localStorage.setItem(SAVEKEY, newSelection);
|
||||||
|
this.setState({
|
||||||
|
saveLocation : newSelection
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
renderButton : function(name, key, shouldRender=true){
|
||||||
|
if(!shouldRender) return;
|
||||||
|
return <button className={this.state.saveLocation==key ? 'active' : ''} onClick={()=>{this.makeActive(key);}}>{name}</button>;
|
||||||
|
},
|
||||||
|
|
||||||
renderNavItems : function() {
|
renderNavItems : function() {
|
||||||
return <Navbar>
|
return <Navbar>
|
||||||
@@ -61,6 +84,11 @@ const AccountPage = createClass({
|
|||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
<div className='dataGroup'>
|
||||||
|
<h4>Default Save Location</h4>
|
||||||
|
{this.renderButton('Homebrewery', 'HOMEBREWERY')}
|
||||||
|
{this.renderButton('Google Drive', 'GOOGLE-DRIVE', this.state.uiItems.googleId)}
|
||||||
|
</div>
|
||||||
</>;
|
</>;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,23 @@
|
|||||||
margin : 5px 0px;
|
margin : 5px 0px;
|
||||||
border : 2px solid black;
|
border : 2px solid black;
|
||||||
border-radius : 5px;
|
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 {
|
h1, h2, h3, h4 {
|
||||||
width : 100%;
|
width : 100%;
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|||||||
|
|
||||||
const { DEFAULT_BREW } = require('../../../../server/brewDefaults.js');
|
const { DEFAULT_BREW } = require('../../../../server/brewDefaults.js');
|
||||||
|
|
||||||
const BREWKEY = 'homebrewery-new';
|
const BREWKEY = 'homebrewery-new';
|
||||||
const STYLEKEY = 'homebrewery-new-style';
|
const STYLEKEY = 'homebrewery-new-style';
|
||||||
const METAKEY = 'homebrewery-new-meta';
|
const METAKEY = 'homebrewery-new-meta';
|
||||||
|
let SAVEKEY;
|
||||||
|
|
||||||
|
|
||||||
const NewPage = createClass({
|
const NewPage = createClass({
|
||||||
@@ -55,6 +56,9 @@ const NewPage = createClass({
|
|||||||
const styleStorage = localStorage.getItem(STYLEKEY);
|
const styleStorage = localStorage.getItem(STYLEKEY);
|
||||||
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
||||||
|
|
||||||
|
SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${global.account.username}`;
|
||||||
|
const saveStorage = localStorage.getItem(SAVEKEY) || 'HOMEBREWERY';
|
||||||
|
|
||||||
brew.text = brewStorage ?? brew.text;
|
brew.text = brewStorage ?? brew.text;
|
||||||
brew.style = styleStorage ?? brew.style;
|
brew.style = styleStorage ?? brew.style;
|
||||||
// brew.title = metaStorage?.title || this.state.brew.title;
|
// brew.title = metaStorage?.title || this.state.brew.title;
|
||||||
@@ -64,7 +68,8 @@ const NewPage = createClass({
|
|||||||
brew.lang = metaStorage?.lang ?? brew.lang;
|
brew.lang = metaStorage?.lang ?? brew.lang;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
brew : brew
|
brew : brew,
|
||||||
|
saveGoogle : (saveStorage == 'GOOGLE-DRIVE' && this.state.saveGoogle)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user