mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
feat: search
This commit is contained in:
1 parent
385cc3b6d2
commit
d6e37119a8
12 files changed
+98
-17
No files matched your search
@@ -1,10 +1,16 @@
|
||||
import fuzzysort from "fuzzysort";
|
||||
import { useMemo } from "react";
|
||||
import { TankCard } from "../../../components/TankCard";
|
||||
import { TankCards } from "../../../components/TankCards";
|
||||
import { TankSearch } from "../../../components/TankSearch";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { useAwait } from "../../../hooks/useAwait";
|
||||
import { LocaleProvider } from "../../../hooks/useLocale";
|
||||
import { useSearchableTanks } from "../../../hooks/useSearchableTanks";
|
||||
import { useTierCompare } from "../../../hooks/useTierCompare";
|
||||
import { TankFilters } from "../../../stores/tankFilters";
|
||||
|
||||
const { go } = fuzzysort;
|
||||
|
||||
interface PageProps {
|
||||
locale: string;
|
||||
@@ -20,7 +26,11 @@ export function Page({ locale, ...props }: PageProps) {
|
||||
|
||||
function Content() {
|
||||
const tanks = useAwait(() => api.tanks(), "tanks");
|
||||
|
||||
const compareTiers = useTierCompare();
|
||||
const searchableTanks = useSearchableTanks();
|
||||
const search = TankFilters.use((state) => state.search);
|
||||
|
||||
const tanksOrdered = useMemo(() => {
|
||||
let list = Object.values(tanks.tanks);
|
||||
|
||||
@@ -30,12 +40,24 @@ function Content() {
|
||||
|
||||
return list;
|
||||
}, []);
|
||||
const tanksFiltered = useMemo(() => {
|
||||
if (!search) return tanksOrdered;
|
||||
|
||||
const results = go(search, searchableTanks, {
|
||||
keys: ["id", "name", "deburred"],
|
||||
});
|
||||
|
||||
return results.map(({ obj }) => obj);
|
||||
}, [search]);
|
||||
|
||||
return (
|
||||
<TankCards>
|
||||
{tanksOrdered.slice(0, 32).map(({ id }) => (
|
||||
<TankCard key={id} id={id} />
|
||||
))}
|
||||
</TankCards>
|
||||
<>
|
||||
<TankSearch />
|
||||
<TankCards>
|
||||
{tanksFiltered.slice(0, 32).map(({ id }) => (
|
||||
<TankCard key={id} id={id} />
|
||||
))}
|
||||
</TankCards>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user