fix: no page memo

This commit is contained in:
TrèsAbhi committed 2024-02-22 18:11:06 -06:00
1 parent 62cb2c7217
commit 8467fb98d6
1 file changed
+18 -18
@@ -357,13 +357,16 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
} }
return sort.direction === 'ascending' ? sorted : sorted.reverse(); return sort.direction === 'ascending' ? sorted : sorted.reverse();
}, [filters, sort]); }, [
sort,
...Object.entries(filters)
.filter(([name]) => name !== 'page')
.map(([, value]) => value),
]);
const [searchResults, setSearchedList] = useState(searchableTanks); const [searchResults, setSearchedList] = useState(searchableTanks);
const page = useTankopediaPersistent((state) => state.filters.page); const page = useTankopediaPersistent((state) => state.filters.page);
const chunkSize = const wideFormat = typeof window !== 'undefined' && window.innerWidth > 512;
typeof window !== 'undefined' && window.innerWidth > 512 const chunkSize = wideFormat ? tanksPerPage / 2 : Infinity;
? tanksPerPage / 2
: Infinity;
const searchResultsPageSlice = searchResults.slice( const searchResultsPageSlice = searchResults.slice(
page * tanksPerPage, page * tanksPerPage,
(page + 1) * tanksPerPage, (page + 1) * tanksPerPage,
@@ -396,19 +399,16 @@ export function TankSearch({ compact, onSelect = () => {} }: TankSearchProps) {
ref={input} ref={input}
placeholder="Search tanks..." placeholder="Search tanks..."
onChange={(event) => { onChange={(event) => {
if (event.target.value.length === 0) { const results = go(event.target.value, searchableTanks, {
setSearchedList(searchableTanks); keys: [
} else { 'name',
setSearchedList( 'nameFull',
go(event.target.value, searchableTanks, { 'id',
keys: [ ] satisfies (keyof TankDefinition)[],
'name', all: true,
'nameFull', }).map(({ obj }) => obj);
'id',
] satisfies (keyof TankDefinition)[], setSearchedList(results);
}).map(({ obj }) => obj),
);
}
}} }}
/> />
</TextField.Root> </TextField.Root>