Skip to content

Commit

Permalink
fix: some pokestop filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 10, 2024
1 parent 93234c3 commit ef6be7f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
7 changes: 4 additions & 3 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/dialogs/filters/FilterMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function FilterMenu() {

React.useEffect(() => {
setTempFilters(filters?.filter)
}, [category])
}, [category, filters?.filter])

return (
<DialogWrapper
Expand Down
18 changes: 9 additions & 9 deletions src/components/layout/general/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Menu({

const [filterDrawer, setFilterDrawer] = useState(false)

const { filteredObj, filteredArr, count } = useFilter(
const { filteredArr, count } = useFilter(
tempFilters,
menus,
category,
Expand All @@ -68,9 +68,8 @@ export default function Menu({
[category, categories, count.total, count.show],
)

const footerButtons = React.useMemo(() => {
const selectedIds = Object.keys(filteredObj)
return [
const footerButtons = React.useMemo(
() => [
{
name: 'help',
action: () =>
Expand All @@ -89,27 +88,28 @@ export default function Menu({
open: true,
id: 'global',
category,
selectedIds,
selectedIds: filteredArr,
},
}),
icon: category === 'pokemon' || webhookCategory ? 'Tune' : 'FormatSize',
},
{
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 (
<>
Expand Down
32 changes: 14 additions & 18 deletions src/hooks/useFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function useFilter(
const search = useGetDeepStore(`searches.${category}Advanced`)
const {
available,
Icons,
auth: { perms },
masterfile: { pokemon },
menuFilters,
Expand All @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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':
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -254,5 +250,5 @@ export default function useFilter(

useEffect(() => () => useStatic.setState({ excludeList: [] }))

return { filteredObj, filteredArr, count }
return { filteredArr, count }
}

0 comments on commit ef6be7f

Please sign in to comment.