Skip to content

Commit

Permalink
feat: allow enable/disable all Pokemon by user choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Dec 20, 2024
1 parent 9685b24 commit 9fb95f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/hooks/useMapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ export function useMapData(once = false) {
}
},
)
const defaultEnabled = prev.filters?.pokemon?.filter?.global?.enabled
if (
defaultEnabled !== undefined &&
defaultEnabled !== filters.pokemon.filter.global.enabled
)
Object.entries(newFilters.pokemon.filter).forEach(([key, filter]) => {
if (prev.filters.pokemon.filter[key] === undefined)
filter.enabled = defaultEnabled
})
return {
filters: newFilters,
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/applyToAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ export function applyToAll(
const userFilters = localFilters.filter ?? {}

const serverFilters = useMemory.getState().filters[category]
const staticFilters = serverFilters?.filter ?? {}
const staticFilters = Object.entries(serverFilters?.filter ?? {})
const refFilter = serverFilters?.standard ?? STANDARD_BACKUP

const idSet = new Set(selectedIds ?? [])
if (category === 'pokemon' && selectedIds.length >= staticFilters.length - 1)
idSet.add('global')

const newObj = Object.fromEntries(
Object.keys(staticFilters).flatMap((key) => {
const filter = userFilters[key] ?? staticFilters[key] ?? refFilter
staticFilters.flatMap(([key, staticFilter]) => {
const filter = userFilters[key] ?? staticFilter ?? refFilter
const filters = [
[
key,
Expand Down

0 comments on commit 9fb95f1

Please sign in to comment.