diff --git a/client/homebrew/pages/basePages/listPage/listPage.jsx b/client/homebrew/pages/basePages/listPage/listPage.jsx index b3e35922b..6719fedac 100644 --- a/client/homebrew/pages/basePages/listPage/listPage.jsx +++ b/client/homebrew/pages/basePages/listPage/listPage.jsx @@ -13,7 +13,7 @@ const USERPAGE_GROUP_VISIBILITY_PREFIX = 'HB_listPage_visibility_group'; const DEFAULT_SORT_TYPE = 'alpha'; const DEFAULT_SORT_DIR = 'asc'; -const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navItems = <>>, reportError = null, query }) => { +const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navItems = <>>, reportError = null, query })=>{ const [filterString, setFilterString] = useState(query?.filter || ''); const [filterTags, setFilterTags] = useState([]); const [sortType, setSortType] = useState(query?.sort || null); @@ -24,27 +24,27 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI const sortTypeRef = useRef(sortType); const sortDirRef = useRef(sortDir); - useEffect(() => { + useEffect(()=>{ groupVisibilityRef.current = groupVisibility; }, [groupVisibility]); - useEffect(() => { + useEffect(()=>{ sortTypeRef.current = sortType; }, [sortType]); - useEffect(() => { + useEffect(()=>{ sortDirRef.current = sortDir; }, [sortDir]); - useEffect(() => { + useEffect(()=>{ window.onbeforeunload = saveToLocalStorage; - if (typeof window !== 'undefined') { + if(typeof window !== 'undefined') { const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE); const newSortDir = sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR); updateUrl(filterString, newSortType, newSortDir); - const namedBrewCollection = brewCollection.reduce((visibility, brewGroup) => { + const namedBrewCollection = brewCollection.reduce((visibility, brewGroup)=>{ visibility[brewGroup.class] = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true') == 'true'; return visibility; }, {}); @@ -54,29 +54,29 @@ const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navI setSortDir(newSortDir); } - return () => { + return ()=>{ window.onbeforeunload = null; }; }, []); - const saveToLocalStorage = () => { - brewCollection.forEach((brewGroup) => { + 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) => { - if (!brews || !brews.length) return