Skip to content

Commit

Permalink
fix: memo comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Sep 10, 2024
1 parent f720aa3 commit dd66d03
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
36 changes: 21 additions & 15 deletions server/src/models/Station.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Station extends Model {
)

if (!onlyAllStations) {
query.whereNotNull('battle_pokemon_id')
if (onlyBattleTier === 'all') {
const battleBosses = new Set()
const battleForms = new Set()
Expand Down Expand Up @@ -90,25 +91,30 @@ class Station extends Model {
}
}

query.select(select)

if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
/** @type {import("@rm/types").FullStation[]} */
const results = await query

return results.filter(
(station) =>
onlyAllStations ||
!perms.dynamax ||
args.filters[`j${station.battle_level}`] ||
args.filters[
`${station.battle_pokemon_id}-${station.battle_pokemon_form}`
] ||
onlyBattleTier === 'all' ||
onlyBattleTier === station.battle_level,
)
const results = await query.select(select)

return results
.filter(
(station) =>
onlyAllStations ||
!perms.dynamax ||
args.filters[`j${station.battle_level}`] ||
args.filters[
`${station.battle_pokemon_id}-${station.battle_pokemon_form}`
] ||
onlyBattleTier === 'all' ||
onlyBattleTier === station.battle_level,
)
.map((station) => {
if (station.is_battle_available && station.battle_pokemon_id === null) {
station.is_battle_available = false
}
return station
})
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/features/drawer/Stations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { SelectorListMemo } from './components/SelectorList'
function StationLevels() {
const { t } = useTranslation()
const available = useMemory((s) => s.available.stations)
const enabled = useStorage((s) => !!s.filters?.stations?.maxBattles)
const enabled = useStorage(
(s) =>
!!s.filters?.stations?.maxBattles && !s.filters?.stations?.allStations,
)
const [filters, setFilters] = useDeepStore(
'filters.stations.battleTier',
'all',
Expand Down Expand Up @@ -56,7 +59,8 @@ function StationsQuickSelect() {
const enabled = useStorage(
(s) =>
!!s.filters?.stations?.maxBattles &&
s.filters?.stations?.battleTier === 'all',
s.filters?.stations?.battleTier === 'all' &&
!s.filters?.stations?.allStations,
)
return (
<CollapsibleItem open={enabled}>
Expand Down
9 changes: 6 additions & 3 deletions src/features/station/StationTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ const BaseStationTile = (station) => {
)
}

function compareValueOrFalsy(prev, next) {
return prev === next || (!prev && !next)
}

export const StationTile = React.memo(
BaseStationTile,
(prev, next) =>
prev.id === next.id &&
prev.battle_level === next.battle_level &&
prev.battle_pokemon_id === next.battle_pokemon_id &&
prev.battle_pokemon_form === next.battle_pokemon_form &&
compareValueOrFalsy(prev.battle_level, next.battle_level) &&
compareValueOrFalsy(prev.battle_pokemon_id, next.battle_pokemon_id) &&
prev.start_time === next.start_time &&
prev.end_time === next.end_time,
)

0 comments on commit dd66d03

Please sign in to comment.