diff --git a/client/homebrew/pages/basePages/listPage/listPage.jsx b/client/homebrew/pages/basePages/listPage/listPage.jsx
index e546e2c7f..25603255c 100644
--- a/client/homebrew/pages/basePages/listPage/listPage.jsx
+++ b/client/homebrew/pages/basePages/listPage/listPage.jsx
@@ -6,28 +6,58 @@ const moment = require('moment');
const BrewItem = require('./brewItem/brewItem.jsx');
+const USERPAGE_KEY_PREFIX = 'HOMEBREWERY-LISTPAGE-VISIBILITY';
+
const ListPage = createClass({
displayName : 'ListPage',
getDefaultProps : function() {
return {
brewCollection : [
{
- title : '',
- class : '',
- brews : []
+ title : '',
+ class : '',
+ brews : [],
+ visible : true
}
],
navItems : <>>
};
},
getInitialState : function() {
+ let brewCollection = [];
+
+ if(typeof window !== 'undefined') {
+ brewCollection = this.props.brewCollection.map((brewGroup)=>{
+ const localVisibility = localStorage.getItem(`${USERPAGE_KEY_PREFIX}-${brewGroup.class}`) ?? 'true';
+ if(brewGroup.visible != (localVisibility=='true')) {
+ brewGroup.visible = (localVisibility=='true');
+ };
+ return brewGroup;
+ });
+ }
+
return {
- sortType : 'alpha',
- sortDir : 'asc',
- filterString : this.props.query?.filter || '',
- query : this.props.query
+ sortType : 'alpha',
+ sortDir : 'asc',
+ filterString : this.props.query?.filter || '',
+ query : this.props.query,
+ brewCollection : brewCollection
};
},
+ componentDidMount : function() {
+ // SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
+ window.onbeforeunload = this.saveToLocalStorage;
+ },
+
+ componentWillUnmount : function() {
+ window.onbeforeunload = function(){};
+ },
+
+ saveToLocalStorage : function() {
+ this.state.brewCollection.map((brewGroup)=>{
+ localStorage.setItem(`${USERPAGE_KEY_PREFIX}-${brewGroup.class}`, `${brewGroup.visible}`);
+ });
+ },
renderBrews : function(brews){
if(!brews || !brews.length) return
No Brews.
;
@@ -149,11 +179,22 @@ const ListPage = createClass({
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
},
+ toggleBrewCollectionState : function(brewGroupClass) {
+ this.setState((prevState)=>({
+ brewCollection : prevState.brewCollection.map(
+ (brewGroup)=>brewGroup.class === brewGroupClass ? { ...brewGroup, visible: !brewGroup.visible } : brewGroup
+ )
+ }));
+ },
+
renderBrewCollection : function(brewCollection){
+ if(brewCollection == []) return
+
No Brews
+ ;
return _.map(brewCollection, (brewGroup, idx)=>{
return
-
{brewGroup.title || 'No Title'}
- {this.renderBrews(this.getSortedBrews(brewGroup.brews))}
+ {this.toggleBrewCollectionState(brewGroup.class);}}>{brewGroup.title || 'No Title'}
+ {brewGroup.visible ? this.renderBrews(this.getSortedBrews(brewGroup.brews)) : <>>}
;
});
},
@@ -166,7 +207,7 @@ const ListPage = createClass({
{this.renderSortOptions()}
- {this.renderBrewCollection(this.props.brewCollection)}
+ {this.renderBrewCollection(this.state.brewCollection)}
;
diff --git a/client/homebrew/pages/basePages/listPage/listPage.less b/client/homebrew/pages/basePages/listPage/listPage.less
index 64131e35b..317dd88ff 100644
--- a/client/homebrew/pages/basePages/listPage/listPage.less
+++ b/client/homebrew/pages/basePages/listPage/listPage.less
@@ -74,4 +74,27 @@
}
}
}
+ h1 {
+ cursor: pointer;
+ &.active {
+ color: #58180D;
+ }
+ &.active::before {
+ content: '\f107';
+ font-family: 'Font Awesome 5 Free';
+ font-weight: 900;
+ font-size: 0.6cm;
+ padding-right: 0.5em;
+ }
+ &.inactive {
+ color: #707070;
+ }
+ &.inactive::before {
+ content: '\f105';
+ font-family: 'Font Awesome 5 Free';
+ font-weight: 900;
+ font-size: 0.6cm;
+ padding-right: 0.5em;
+ }
+ }
}
diff --git a/client/homebrew/pages/userPage/userPage.jsx b/client/homebrew/pages/userPage/userPage.jsx
index 6c3af7907..861351c6f 100644
--- a/client/homebrew/pages/userPage/userPage.jsx
+++ b/client/homebrew/pages/userPage/userPage.jsx
@@ -31,17 +31,19 @@ const UserPage = createClass({
const brewCollection = [
{
- title : `${usernameWithS} published brews`,
- class : 'published',
- brews : brews.published
+ title : `${usernameWithS} published brews`,
+ class : 'published',
+ brews : brews.published,
+ visible : true
}
];
if(this.props.username == global.account?.username){
brewCollection.push(
{
- title : `${usernameWithS} unpublished brews`,
- class : 'unpublished',
- brews : brews.private
+ title : `${usernameWithS} unpublished brews`,
+ class : 'unpublished',
+ brews : brews.private,
+ visible : true
}
);
}