2026-04-27 19:57:44 -05:00
|
|
|
import fuzzysort from "fuzzysort";
|
2026-04-27 19:34:06 -05:00
|
|
|
import { useMemo } from "react";
|
2026-04-26 18:19:09 -05:00
|
|
|
import { TankCard } from "../../../components/TankCard";
|
|
|
|
|
import { TankCards } from "../../../components/TankCards";
|
2026-04-27 19:57:44 -05:00
|
|
|
import { TankSearch } from "../../../components/TankSearch";
|
2026-04-26 18:19:09 -05:00
|
|
|
import { api } from "../../../core/api/dynamic";
|
|
|
|
|
import { useAwait } from "../../../hooks/useAwait";
|
|
|
|
|
import { LocaleProvider } from "../../../hooks/useLocale";
|
2026-04-27 19:57:44 -05:00
|
|
|
import { useSearchableTanks } from "../../../hooks/useSearchableTanks";
|
2026-04-27 19:34:06 -05:00
|
|
|
import { useTierCompare } from "../../../hooks/useTierCompare";
|
2026-04-27 19:57:44 -05:00
|
|
|
import { TankFilters } from "../../../stores/tankFilters";
|
|
|
|
|
|
|
|
|
|
const { go } = fuzzysort;
|
2026-04-26 18:19:09 -05:00
|
|
|
|
|
|
|
|
interface PageProps {
|
|
|
|
|
locale: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Page({ locale, ...props }: PageProps) {
|
|
|
|
|
return (
|
|
|
|
|
<LocaleProvider locale={locale}>
|
|
|
|
|
<Content {...props} />
|
|
|
|
|
</LocaleProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Content() {
|
2026-04-27 19:34:06 -05:00
|
|
|
const tanks = useAwait(() => api.tanks(), "tanks");
|
2026-04-27 19:57:44 -05:00
|
|
|
|
2026-04-27 19:34:06 -05:00
|
|
|
const compareTiers = useTierCompare();
|
2026-04-27 19:57:44 -05:00
|
|
|
const searchableTanks = useSearchableTanks();
|
|
|
|
|
const search = TankFilters.use((state) => state.search);
|
|
|
|
|
|
2026-04-27 19:34:06 -05:00
|
|
|
const tanksOrdered = useMemo(() => {
|
|
|
|
|
let list = Object.values(tanks.tanks);
|
|
|
|
|
|
2026-04-28 15:11:20 -05:00
|
|
|
list = list.sort((a, b) => a.tank!.tank_type - b.tank!.tank_type);
|
|
|
|
|
list = list.sort((a, b) => a.tank!.tank_class - b.tank!.tank_class);
|
|
|
|
|
list = list.sort((a, b) => a.tank!.nation - b.tank!.nation);
|
2026-04-27 19:34:06 -05:00
|
|
|
list = list.sort((a, b) =>
|
|
|
|
|
compareTiers(a.tank!.tier_catalog_id, b.tank!.tier_catalog_id),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}, []);
|
2026-04-27 19:57:44 -05:00
|
|
|
const tanksFiltered = useMemo(() => {
|
|
|
|
|
if (!search) return tanksOrdered;
|
|
|
|
|
|
|
|
|
|
const results = go(search, searchableTanks, {
|
|
|
|
|
keys: ["id", "name", "deburred"],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return results.map(({ obj }) => obj);
|
|
|
|
|
}, [search]);
|
2026-04-26 18:19:09 -05:00
|
|
|
|
|
|
|
|
return (
|
2026-04-27 19:57:44 -05:00
|
|
|
<>
|
|
|
|
|
<TankSearch />
|
|
|
|
|
<TankCards>
|
|
|
|
|
{tanksFiltered.slice(0, 32).map(({ id }) => (
|
|
|
|
|
<TankCard key={id} id={id} />
|
|
|
|
|
))}
|
|
|
|
|
</TankCards>
|
|
|
|
|
</>
|
2026-04-26 18:19:09 -05:00
|
|
|
);
|
|
|
|
|
}
|