Skip to content

Commit a39e59f

Browse files
committed
fix: rename utils for cleanup
fix: clean outdated storage 15s after map loads
1 parent cfbfd09 commit a39e59f

File tree

10 files changed

+39
-17
lines changed

10 files changed

+39
-17
lines changed

src/features/drawer/settings/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { LocaleSelection } from '@components/inputs/LocaleSelection'
2323
import { DividerWithMargin } from '@components/StyledDivider'
2424
import { BoolToggle } from '@components/inputs/BoolToggle'
2525
import { BasicListButton } from '@components/inputs/BasicListButton'
26-
import { clearHiddenEntities } from '@utils/pokemon/hiddenPokemon'
26+
import { clearHiddenEntities } from '@utils/hiddenEntities'
2727

2828
import { DrawerActions } from '../components/Actions'
2929
import { GeneralSetting } from './General'

src/features/gym/GymPopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { getTimeUntil } from '@utils/getTimeUntil'
3737
import { formatInterval } from '@utils/formatInterval'
3838
import { usePokemonBackgroundVisuals } from '@hooks/usePokemonBackgroundVisuals'
3939
import { getFormDisplay } from '@utils/getFormDisplay'
40-
import { addHiddenEntity, showHideSnackbar } from '@utils/pokemon/hiddenPokemon'
40+
import { addHiddenEntity, showHideSnackbar } from '@utils/hiddenEntities'
4141

4242
import { useWebhook } from './useWebhook'
4343

src/features/nest/NestPopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { setDeepStore } from '@store/useStorage'
1616
import { getTimeUntil } from '@utils/getTimeUntil'
1717
import { useAnalytics } from '@hooks/useAnalytics'
1818
import { Navigation } from '@components/popups/Navigation'
19-
import { addHiddenEntity, showHideSnackbar } from '@utils/pokemon/hiddenPokemon'
19+
import { addHiddenEntity, showHideSnackbar } from '@utils/hiddenEntities'
2020

2121
/** @param {number} timeSince */
2222
const getColor = (timeSince) => {

src/features/pokemon/PokemonPopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { GET_TAPPABLE_BY_ID } from '@services/queries/tappable'
3333
import { usePokemonBackgroundVisual } from '@hooks/usePokemonBackgroundVisuals'
3434
import { BackgroundCard } from '@components/popups/BackgroundCard'
3535
import { getFormDisplay } from '@utils/getFormDisplay'
36-
import { addHiddenEntity } from '@utils/pokemon/hiddenPokemon'
36+
import { addHiddenEntity } from '@utils/hiddenEntities'
3737

3838
const rowClass = { width: 30, fontWeight: 'bold' }
3939

src/features/pokestop/PokestopPopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { useGetAvailable } from '@hooks/useGetAvailable'
3535
import { parseQuestConditions } from '@utils/parseConditions'
3636
import { Img } from '@components/Img'
3737
import { readableProbability } from '@utils/readableProbability'
38-
import { addHiddenEntity, showHideSnackbar } from '@utils/pokemon/hiddenPokemon'
38+
import { addHiddenEntity, showHideSnackbar } from '@utils/hiddenEntities'
3939
import {
4040
usePokemonBackgroundVisuals,
4141
usePokemonBackgroundVisual,

src/features/station/StationPopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Img, PokemonImg } from '@components/Img'
2727
import { useFormatStore } from '@store/useFormatStore'
2828
import { useRelativeTimer } from '@hooks/useRelativeTime'
2929
import { useAnalytics } from '@hooks/useAnalytics'
30-
import { addHiddenEntity, showHideSnackbar } from '@utils/pokemon/hiddenPokemon'
30+
import { addHiddenEntity, showHideSnackbar } from '@utils/hiddenEntities'
3131
import { BackgroundCard } from '@components/popups/BackgroundCard'
3232
import { Title } from '@components/popups/Title'
3333
import {

src/features/tappable/TappablePopup.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { StatusIcon } from '@components/StatusIcon'
2020
import { Title } from '@components/popups/Title'
2121

2222
import { getTimeUntil } from '@utils/getTimeUntil'
23-
import { addHiddenEntity, showHideSnackbar } from '@utils/pokemon/hiddenPokemon'
23+
import { addHiddenEntity, showHideSnackbar } from '@utils/hiddenEntities'
2424

2525
import { getTappableDisplaySettings } from './displayRules'
2626

src/pages/map/components/Container.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ScanOnDemand } from '@features/scanner'
99
import { WebhookMarker, WebhookAreaSelection } from '@features/webhooks'
1010
import { ActiveWeather } from '@features/weather'
1111
import { timeCheck } from '@utils/timeCheck'
12+
import { cleanupHiddenEntities } from '@utils/hiddenEntities'
1213

1314
import { Effects } from './Effects'
1415
import { DataView } from './Data'
@@ -38,6 +39,14 @@ const MAX_BOUNDS = /** @type {[[number, number], [number, number]]} */ ([
3839
export function Container() {
3940
const { location, zoom } = useStorage.getState()
4041

42+
// Cleanup hidden entities 15 seconds after map loads
43+
React.useEffect(() => {
44+
const timer = setTimeout(() => {
45+
cleanupHiddenEntities(useMemory.setState)
46+
}, 15000)
47+
return () => clearTimeout(timer)
48+
}, [])
49+
4150
return (
4251
<MapContainer
4352
tap={false}

src/store/useMemory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { create } from 'zustand'
44

5-
import { getHiddenEntitySet } from '@utils/pokemon/hiddenPokemon'
5+
import { getHiddenEntitySet } from '@utils/hiddenEntities'
66

77
/**
88
* TODO: Finish this
Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
const STORAGE_KEY = 'pokemon-hide-list'
4-
const SNACKBAR_COUNT_KEY = 'pokemon-hide-snackbar-count'
3+
const STORAGE_KEY = 'hidden-entities'
4+
const SNACKBAR_COUNT_KEY = 'hidden-entities-snackbar-count'
55
const MAX_AGE_MS = 60 * 60 * 1000 // 1 hour
66
const MAX_SNACKBAR_SHOWS = 3
77

@@ -10,7 +10,7 @@ const MAX_SNACKBAR_SHOWS = 3
1010
*/
1111

1212
/**
13-
* Load hidden Pokemon entries from localStorage
13+
* Load hidden entries from localStorage
1414
* @returns {HiddenEntry[]}
1515
*/
1616
function loadEntries() {
@@ -25,7 +25,7 @@ function loadEntries() {
2525
}
2626

2727
/**
28-
* Save hidden Pokemon entries to localStorage
28+
* Save hidden entries to localStorage
2929
* @param {HiddenEntry[]} entries
3030
*/
3131
function saveEntries(entries) {
@@ -47,12 +47,12 @@ function cleanOldEntries(entries) {
4747
}
4848

4949
/**
50-
* Add an entity ID to the hidden list with timestamp, cleaning old entries
50+
* Add an entity ID to the hidden list with timestamp
5151
* @param {string | number} id
5252
* @returns {Set<string | number>} Updated hideList Set
5353
*/
5454
export function addHiddenEntity(id) {
55-
const entries = cleanOldEntries(loadEntries())
55+
const entries = loadEntries()
5656
if (!entries.some((e) => e.id === id)) {
5757
entries.push({ id, ts: Date.now() })
5858
}
@@ -61,15 +61,28 @@ export function addHiddenEntity(id) {
6161
}
6262

6363
/**
64-
* Get the current hidden entity Set from localStorage (cleaned)
64+
* Get the current hidden entity Set from localStorage
6565
* @returns {Set<string | number>}
6666
*/
6767
export function getHiddenEntitySet() {
68-
const entries = cleanOldEntries(loadEntries())
69-
saveEntries(entries) // persist cleaned list
68+
const entries = loadEntries()
7069
return new Set(entries.map((e) => e.id))
7170
}
7271

72+
/**
73+
* Clean outdated hidden entries (older than 1 hour) from localStorage
74+
* Updates both localStorage and the in-memory hideList
75+
* @param {(state: { hideList: Set<string | number> }) => void} setState
76+
*/
77+
export function cleanupHiddenEntities(setState) {
78+
const entries = loadEntries()
79+
const cleaned = cleanOldEntries(entries)
80+
if (cleaned.length !== entries.length) {
81+
saveEntries(cleaned)
82+
setState({ hideList: new Set(cleaned.map((e) => e.id)) })
83+
}
84+
}
85+
7386
/** @type {{ current: number | null }} */
7487
const snackbarTimer = { current: null }
7588

0 commit comments

Comments
 (0)