/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/ require('./listPage.less'); const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const moment = require('moment'); const BrewItem = require('./brewItem/brewItem.jsx'); const USERPAGE_KEY_PREFIX = 'HOMEBREWERY-LISTPAGE'; const DEFAULT_SORT_TYPE = 'alpha'; const DEFAULT_SORT_DIR = 'asc'; const ListPage = createClass({ displayName : 'ListPage', getDefaultProps : function() { return { brewCollection : [ { title : '', class : '', brews : [] } ], navItems : <>> }; }, getInitialState : function() { // HIDE ALL GROUPS UNTIL LOADED const brewCollection = this.props.brewCollection.map((brewGroup)=>{ brewGroup.visible = false; return brewGroup; }); return { filterString : this.props.query?.filter || '', sortType : this.props.query?.sort || null, sortDir : this.props.query?.dir || null, query : this.props.query, brewCollection : brewCollection }; }, componentDidMount : function() { // SAVE TO LOCAL STORAGE WHEN LEAVING PAGE window.onbeforeunload = this.saveToLocalStorage; // LOAD FROM LOCAL STORAGE if(typeof window !== 'undefined') { const newSortType = (this.state.sortType ?? (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-SORTTYPE`) || DEFAULT_SORT_TYPE)); const newSortDir = (this.state.sortDir ?? (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-SORTDIR`) || DEFAULT_SORT_DIR)); this.updateUrl(this.state.filterString, newSortType, newSortDir); const brewCollection = this.props.brewCollection.map((brewGroup)=>{ brewGroup.visible = (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-VISIBILITY-${brewGroup.class}`) ?? 'true')=='true'; return brewGroup; }); this.setState({ brewCollection : brewCollection, sortType : newSortType, sortDir : newSortDir }); }; }, componentWillUnmount : function() { window.onbeforeunload = function(){}; }, saveToLocalStorage : function() { this.state.brewCollection.map((brewGroup)=>{ localStorage.setItem(`${USERPAGE_KEY_PREFIX}-VISIBILITY-${brewGroup.class}`, `${brewGroup.visible}`); }); localStorage.setItem(`${USERPAGE_KEY_PREFIX}-SORTTYPE`, this.state.sortType); localStorage.setItem(`${USERPAGE_KEY_PREFIX}-SORTDIR`, this.state.sortDir); }, renderBrews : function(brews){ if(!brews || !brews.length) return
Sort by : |
{this.renderSortOption('Title', 'alpha')}
{this.renderSortOption('Created Date', 'created')}
{this.renderSortOption('Updated Date', 'updated')}
{this.renderSortOption('Views', 'views')}
{/* {this.renderSortOption('Latest', 'latest')} */}
Direction : |
{this.renderFilterOption()} |