mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 08:32:41 +00:00
Load from local storage working without errors
This commit is contained in:
@@ -24,17 +24,11 @@ const ListPage = createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
let brewCollection = [];
|
// HIDE ALL GROUPS UNTIL LOADED
|
||||||
|
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
||||||
if(typeof window !== 'undefined') {
|
brewGroup.visible = false;
|
||||||
brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
return brewGroup;
|
||||||
const localVisibility = localStorage.getItem(`${USERPAGE_KEY_PREFIX}-${brewGroup.class}`) ?? 'true';
|
});
|
||||||
if(brewGroup.visible != (localVisibility=='true')) {
|
|
||||||
brewGroup.visible = (localVisibility=='true');
|
|
||||||
};
|
|
||||||
return brewGroup;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sortType : 'alpha',
|
sortType : 'alpha',
|
||||||
@@ -44,9 +38,22 @@ const ListPage = createClass({
|
|||||||
brewCollection : brewCollection
|
brewCollection : brewCollection
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount : function() {
|
componentDidMount : function() {
|
||||||
// SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
|
// SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
|
||||||
window.onbeforeunload = this.saveToLocalStorage;
|
window.onbeforeunload = this.saveToLocalStorage;
|
||||||
|
|
||||||
|
// LOAD FROM LOCAL STORAGE
|
||||||
|
if(typeof window !== 'undefined') {
|
||||||
|
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
||||||
|
const localVisibility = (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-${brewGroup.class}`) ?? 'true')=='true';
|
||||||
|
brewGroup.visible = (brewGroup.visible != localVisibility ? localVisibility : brewGroup.visible);
|
||||||
|
return brewGroup;
|
||||||
|
});
|
||||||
|
this.setState({
|
||||||
|
brewCollection : brewCollection
|
||||||
|
});
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount : function() {
|
componentWillUnmount : function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user