diff --git a/server/src/models/Pokestop.js b/server/src/models/Pokestop.js index 1dc6f694c..fba0210b7 100644 --- a/server/src/models/Pokestop.js +++ b/server/src/models/Pokestop.js @@ -870,9 +870,10 @@ class Pokestop extends Model { if ( quest.quest_timestamp >= midnight && (filters.onlyAllPokestops || - (filters[newQuest.key]?.adv && !filters[newQuest.key].all - ? filters[newQuest.key].adv.includes(quest.quest_title) - : true) || + (filters[newQuest.key] && + (filters[newQuest.key].adv && !filters[newQuest.key].all + ? filters[newQuest.key].adv.includes(quest.quest_title) + : true)) || filters[`u${quest.quest_reward_type}`]) ) { this.fieldAssigner(newQuest, quest, fields) diff --git a/src/components/layout/dialogs/filters/FilterMenu.jsx b/src/components/layout/dialogs/filters/FilterMenu.jsx index d1b8ec148..1b0733f0f 100644 --- a/src/components/layout/dialogs/filters/FilterMenu.jsx +++ b/src/components/layout/dialogs/filters/FilterMenu.jsx @@ -28,7 +28,7 @@ export default function FilterMenu() { React.useEffect(() => { setTempFilters(filters?.filter) - }, [category]) + }, [category, filters?.filter]) return ( { - const selectedIds = Object.keys(filteredObj) - return [ + const footerButtons = React.useMemo( + () => [ { name: 'help', action: () => @@ -89,7 +88,7 @@ export default function Menu({ open: true, id: 'global', category, - selectedIds, + selectedIds: filteredArr, }, }), icon: category === 'pokemon' || webhookCategory ? 'Tune' : 'FormatSize', @@ -97,19 +96,20 @@ export default function Menu({ { name: 'disable_all', action: () => - applyToAll(false, category, selectedIds, !webhookCategory), + applyToAll(false, category, filteredArr, !webhookCategory), icon: 'Clear', color: 'error', }, { name: 'enable_all', - action: () => applyToAll(true, category, selectedIds, !webhookCategory), + action: () => applyToAll(true, category, filteredArr, !webhookCategory), icon: 'Check', color: 'success', }, ...(extraButtons ?? []), - ] - }, [category, webhookCategory, extraButtons, filteredObj, tempFilters]) + ], + [category, webhookCategory, extraButtons, filteredArr, tempFilters], + ) return ( <> diff --git a/src/hooks/useFilter.js b/src/hooks/useFilter.js index 35792c405..c983f1a4f 100644 --- a/src/hooks/useFilter.js +++ b/src/hooks/useFilter.js @@ -21,7 +21,6 @@ export default function useFilter( const search = useGetDeepStore(`searches.${category}Advanced`) const { available, - Icons, auth: { perms }, masterfile: { pokemon }, menuFilters, @@ -40,7 +39,6 @@ export default function useFilter( } = menus[category] const tempAdvFilter = {} const filteredArr = [] - const filteredObj = {} const searchTerms = [] const count = { total: 0, show: 0 } let switchKey @@ -66,10 +64,8 @@ export default function useFilter( switchKey = 'available' } - const addItem = (id, item) => { + const addItem = (id) => { count.show += 1 - item.url = Icons.getIconById(id) - filteredObj[id] = tempFilters[id] filteredArr.push(id) } @@ -135,13 +131,13 @@ export default function useFilter( item.id = id switch (switchKey) { case 'all': - addItem(id, item) + addItem(id) break case 'selected': - if (tempFilters[id]?.enabled) addItem(id, item) + if (tempFilters[id]?.enabled) addItem(id) break case 'unselected': - if (!tempFilters[id]?.enabled) addItem(id, item) + if (!tempFilters[id]?.enabled) addItem(id) break case 'reverse': if (filteringPokemon.includes(subCategory) || item.webhookOnly) { @@ -161,14 +157,14 @@ export default function useFilter( item.formId === item.defaultFormId))) || item.webhookOnly ) { - addItem(id, item) + addItem(id) } } else if ( tempAdvFilter.categories || categories[subCategory] || item.webhookOnly ) { - addItem(id, item) + addItem(id) } break case 'available': @@ -196,14 +192,14 @@ export default function useFilter( item.formId === item.defaultFormId))) || item.webhookOnly ) { - addItem(id, item) + addItem(id) } } else if ( tempAdvFilter.categories || categories[subCategory] || item.webhookOnly ) { - addItem(id, item) + addItem(id) } } break @@ -214,15 +210,15 @@ export default function useFilter( case 'string': term = term.trim() if (meta.includes(term) || item.pokedexId == term) { - addItem(id, item) + addItem(id) } break case 'number': - if (item.family === term) addItem(id, item) + if (item.family === term) addItem(id) break default: if (term.every((subTerm) => meta.includes(subTerm))) - addItem(id, item) + addItem(id) } }) break @@ -240,10 +236,10 @@ export default function useFilter( categories[subCategory] || item.webhookOnly ) { - addItem(id, item) + addItem(id) } } else if (categories[subCategory] || item.webhookOnly) { - addItem(id, item) + addItem(id) } break } @@ -254,5 +250,5 @@ export default function useFilter( useEffect(() => () => useStatic.setState({ excludeList: [] })) - return { filteredObj, filteredArr, count } + return { filteredArr, count } }