Skip to content

Commit

Permalink
fix: prevent users from loading too many s2 cells
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jul 1, 2024
1 parent a4d6865 commit 8f8a03d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@
"rocket_pokemon": "Rocket Pokémon",
"decoy": "Decoy",
"s2_cell_limit_0": "You attempted to generate more than 20,000 cells ({{variable_0}})",
"s2_cell_zoom_limit": "Some cells are too small to be displayed at this zoom level",
"show_all_pvp_ranks": "Show All PVP Ranks",
"enable_pokemon_popup_coords": "Show Pokémon Coords",
"enable_gym_popup_coords": "Show Gym Coords",
Expand Down Expand Up @@ -785,4 +786,4 @@
"locale_instructions_8": "Wait for the pull request to be reviewed and merged",
"enter_translation": "Enter Translation",
"individual_filters": "Partially Filtered"
}
}
4 changes: 2 additions & 2 deletions src/features/drawer/pokemon/ModeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FCSelectListItem } from '@components/inputs/FCSelect'
export function PokemonModeSelector() {
const filterMode = useStorage((s) => s.getPokemonFilterMode())
const { t } = useTranslation()
const ui = useMemory((s) => s.ui.pokemon)
const isLegacyEnabled = useMemory((s) => !!s.ui.pokemon?.legacy)
const selectRef = React.useRef(/** @type {HTMLDivElement | null} */ (null))

return (
Expand All @@ -35,7 +35,7 @@ export function PokemonModeSelector() {
}
}}
>
{['basic', 'intermediate', ...(ui.legacy ? ['expert'] : [])].map(
{['basic', 'intermediate', ...(isLegacyEnabled ? ['expert'] : [])].map(
(tier) => (
<MenuItem
key={tier}
Expand Down
15 changes: 11 additions & 4 deletions src/features/s2cell/GenerateCells.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export function GenerateCells() {
: s.userSettings.s2cells.lightMapBorder,
)
/** @type {number[]} */
const filter = useStorage((s) => s.filters.s2cells.cells)
const filter = useStorage((s) => s.filters?.s2cells?.cells)
const location = useStorage((s) => s.location)
const zoom = useStorage((s) => s.zoom)

const cells = React.useMemo(() => {
const bounds = getQueryArgs()
return filter.flatMap((level) => {
return filter?.flatMap((level) => {
if (level > zoom) return []

const regionCoverer = new S2RegionCoverer()
const region = S2LatLngRect.fromLatLng(
S2LatLng.fromDegrees(bounds.minLat, bounds.minLon),
Expand All @@ -55,7 +57,7 @@ export function GenerateCells() {
})
}, [filter, location, zoom, color])

return (
return filter ? (
<>
{cells
.filter((_, i) => i < 20_000)
Expand All @@ -73,6 +75,11 @@ export function GenerateCells() {
},
]}
/>
<Notification
open={filter.some((x) => x > zoom)}
severity="warning"
title="s2_cell_zoom_limit"
/>
</>
)
) : null
}

0 comments on commit 8f8a03d

Please sign in to comment.