feat: search

This commit is contained in:
TrèsAbhi committed 2026-04-27 19:57:44 -05:00
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>
</>
);
}
@@ -2,7 +2,6 @@
import "@radix-ui/colors/violet-dark.css";
import { Section } from "../../../components/Section";
import ToolBanner from "../../../components/ToolBanner.astro";
import { api } from "../../../core/api/dynamic";
import { tools } from "../../../core/tools/tools";
import BaseLayout from "../../../layouts/BaseLayout.astro";
import { Page } from "./_index";
@@ -10,7 +9,6 @@ import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
const tankList = await api.tankList();
---
<BaseLayout {locale} accent="purple">