mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-16 14:28:43 +00:00
Merge branch 'master' of https://github.com/naturalcrit/homebrewery into refactor-combobox
This commit is contained in:
@@ -145,8 +145,8 @@
|
|||||||
box-shadow : 0 4px 5px 0 #333333;
|
box-shadow : 0 4px 5px 0 #333333;
|
||||||
.text {
|
.text {
|
||||||
min-height : 54px;
|
min-height : 54px;
|
||||||
|
padding-left : 5px;
|
||||||
h2 { margin-bottom : 5px; }
|
h2 { margin-bottom : 5px; }
|
||||||
.description { padding-left : 5px; }
|
|
||||||
}
|
}
|
||||||
.info { padding-left : 5px; }
|
.info { padding-left : 5px; }
|
||||||
.links {
|
.links {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
import './listPage.less';
|
import './listPage.less';
|
||||||
import React, { useEffect, useState, useRef, useMemo } from 'react';
|
import React, { useEffect, useState, useMemo } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
@@ -26,24 +26,7 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
const [layoutMode, setLayoutMode] = useState(DEFAULT_LAYOUT_MODE);
|
const [layoutMode, setLayoutMode] = useState(DEFAULT_LAYOUT_MODE);
|
||||||
const [themeMode, setThemeMode] = useState(DEFAULT_THEME_MODE);
|
const [themeMode, setThemeMode] = useState(DEFAULT_THEME_MODE);
|
||||||
|
|
||||||
const groupVisibilityRef = useRef(groupVisibility);
|
|
||||||
const sortTypeRef = useRef(sortType);
|
|
||||||
const sortDirRef = useRef(sortDir);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
groupVisibilityRef.current = groupVisibility;
|
|
||||||
}, [groupVisibility]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
sortTypeRef.current = sortType;
|
|
||||||
}, [sortType]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
sortDirRef.current = sortDir;
|
|
||||||
}, [sortDir]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
window.onbeforeunload = saveToLocalStorage;
|
|
||||||
if(typeof window === 'undefined') return;
|
if(typeof window === 'undefined') return;
|
||||||
|
|
||||||
const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE);
|
const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE);
|
||||||
@@ -63,20 +46,8 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
setSortDir(newSortDir);
|
setSortDir(newSortDir);
|
||||||
setLayoutMode(newLayoutMode);
|
setLayoutMode(newLayoutMode);
|
||||||
setThemeMode(newThemeMode);
|
setThemeMode(newThemeMode);
|
||||||
|
|
||||||
return ()=>{
|
|
||||||
window.onbeforeunload = null;
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const saveToLocalStorage = ()=>{
|
|
||||||
brewCollection.forEach((brewGroup)=>{
|
|
||||||
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`, `${groupVisibilityRef.current[brewGroup.class]}`);
|
|
||||||
});
|
|
||||||
localStorage.setItem(USERPAGE_SORT_TYPE, sortTypeRef.current);
|
|
||||||
localStorage.setItem(USERPAGE_SORT_DIR, sortDirRef.current);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderBrews = (brews)=>{
|
const renderBrews = (brews)=>{
|
||||||
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
||||||
|
|
||||||
@@ -108,6 +79,8 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
const handleSortOptionChange = (event)=>{
|
const handleSortOptionChange = (event)=>{
|
||||||
updateUrl(filterString, event.target.value, sortDir);
|
updateUrl(filterString, event.target.value, sortDir);
|
||||||
setSortType(event.target.value);
|
setSortType(event.target.value);
|
||||||
|
localStorage.setItem(USERPAGE_SORT_TYPE, event.target.value);
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSortDirChange = (event)=>{
|
const handleSortDirChange = (event)=>{
|
||||||
@@ -115,6 +88,8 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
|
|
||||||
updateUrl(filterString, sortType, newDir);
|
updateUrl(filterString, sortType, newDir);
|
||||||
setSortDir(newDir);
|
setSortDir(newDir);
|
||||||
|
localStorage.setItem(USERPAGE_SORT_DIR, newDir);
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSortOption = (sortTitle, sortValue)=>{
|
const renderSortOption = (sortTitle, sortValue)=>{
|
||||||
@@ -257,7 +232,13 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
}, [brewCollection, filterString, filterTags, sortType, sortDir]);
|
}, [brewCollection, filterString, filterTags, sortType, sortDir]);
|
||||||
|
|
||||||
const toggleBrewCollectionState = (brewGroupClass)=>{
|
const toggleBrewCollectionState = (brewGroupClass)=>{
|
||||||
setGroupVisibility((prevVisibility)=>({ ...prevVisibility, [brewGroupClass]: !prevVisibility[brewGroupClass] }));
|
setGroupVisibility((prevVisibility)=>{
|
||||||
|
const visible = !prevVisibility[brewGroupClass];
|
||||||
|
|
||||||
|
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroupClass}`, visible);
|
||||||
|
|
||||||
|
return {...prevVisibility, [brewGroupClass]: visible};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderBrewCollection = (brewCollection)=>{
|
const renderBrewCollection = (brewCollection)=>{
|
||||||
@@ -298,8 +279,8 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
<div className='radio-toggle layout-container'>
|
<div className='radio-toggle layout-container'>
|
||||||
<h6>View:</h6>
|
<h6>View:</h6>
|
||||||
<label className='option' title='grid'>
|
<label className='option' title='grid'>
|
||||||
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'grid')} checked={layoutMode === 'grid'} />
|
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'grid')} checked={layoutMode === 'grid'} />
|
||||||
<i className='fac compressed-grid'></i>
|
<i className='fac compressed-grid'></i>
|
||||||
</label>
|
</label>
|
||||||
<label className='option' title='list'>
|
<label className='option' title='list'>
|
||||||
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'list')} checked={layoutMode === 'list'} />
|
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'list')} checked={layoutMode === 'list'} />
|
||||||
@@ -320,24 +301,24 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
};
|
};
|
||||||
const renderThemePicker = ()=>{
|
const renderThemePicker = ()=>{
|
||||||
return (
|
return (
|
||||||
<div className="radio-toggle theme-container">
|
<div className='radio-toggle theme-container'>
|
||||||
<h6>Theme:</h6>
|
<h6>Theme:</h6>
|
||||||
<label className="option">
|
<label className='option'>
|
||||||
<input type="radio" name="theme" onChange={(e)=>handleThemeChange(e, 'light')} checked={themeMode === 'light'}/>
|
<input type='radio' name='theme' onChange={(e)=>handleThemeChange(e, 'light')} checked={themeMode === 'light'}/>
|
||||||
<i className="fas fa-sun"/>
|
<i className='fas fa-sun'/>
|
||||||
</label>
|
</label>
|
||||||
<label className="option">
|
<label className='option'>
|
||||||
<input type="radio" name="theme" onChange={(e)=>handleThemeChange(e, 'dark')} checked={themeMode === 'dark'}/>
|
<input type='radio' name='theme' onChange={(e)=>handleThemeChange(e, 'dark')} checked={themeMode === 'dark'}/>
|
||||||
<i className="fas fa-moon"/>
|
<i className='fas fa-moon'/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNav = () =>{
|
const renderNav = ()=>{
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="listPageNav">
|
<div className='listPageNav'>
|
||||||
{renderLayoutModeOptions()}
|
{renderLayoutModeOptions()}
|
||||||
{renderThemePicker()}
|
{renderThemePicker()}
|
||||||
{renderSortOptions()}
|
{renderSortOptions()}
|
||||||
@@ -346,7 +327,7 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='sitePage listPage'>
|
<div className='sitePage listPage'>
|
||||||
@@ -354,7 +335,7 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI
|
|||||||
|
|
||||||
{renderNav()}
|
{renderNav()}
|
||||||
|
|
||||||
<div className={`content V3 ${themeMode + 'Mode'}`}>
|
<div className={`content V3 ${`${themeMode}Mode`}`}>
|
||||||
<div className='brewCollection'>{renderBrewCollection(brewCollection)}</div>
|
<div className='brewCollection'>{renderBrewCollection(brewCollection)}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Generated
+3
-3
@@ -7660,9 +7660,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/fast-uri": {
|
"node_modules/fast-uri": {
|
||||||
"version": "3.1.8",
|
"version": "3.1.9",
|
||||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz",
|
||||||
"integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==",
|
"integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user