mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
feat: tier sorting
This commit is contained in:
1 parent
b4936bf13b
commit
385cc3b6d2
8 files changed
+64
-7
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { useMemo } from "react";
|
||||
import { TankCard } from "../../../components/TankCard";
|
||||
import { TankCards } from "../../../components/TankCards";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { useAwait } from "../../../hooks/useAwait";
|
||||
import { LocaleProvider } from "../../../hooks/useLocale";
|
||||
import { useTierCompare } from "../../../hooks/useTierCompare";
|
||||
|
||||
interface PageProps {
|
||||
locale: string;
|
||||
@@ -17,11 +19,21 @@ export function Page({ locale, ...props }: PageProps) {
|
||||
}
|
||||
|
||||
function Content() {
|
||||
const tankList = useAwait(() => api.tankList(), "tank-list");
|
||||
const tanks = useAwait(() => api.tanks(), "tanks");
|
||||
const compareTiers = useTierCompare();
|
||||
const tanksOrdered = useMemo(() => {
|
||||
let list = Object.values(tanks.tanks);
|
||||
|
||||
list = list.sort((a, b) =>
|
||||
compareTiers(a.tank!.tier_catalog_id, b.tank!.tier_catalog_id),
|
||||
);
|
||||
|
||||
return list;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<TankCards>
|
||||
{tankList.list.slice(0, 32).map(({ id }) => (
|
||||
{tanksOrdered.slice(0, 32).map(({ id }) => (
|
||||
<TankCard key={id} id={id} />
|
||||
))}
|
||||
</TankCards>
|
||||
|
||||
@@ -19,8 +19,4 @@ const tankList = await api.tankList();
|
||||
<Section>
|
||||
<Page {locale} client:load />
|
||||
</Section>
|
||||
|
||||
<!-- {
|
||||
|
||||
} -->
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Tiers } from "@protos/blitzkit/tiers";
|
||||
import { api } from "../../core/api/dynamic";
|
||||
|
||||
/**
|
||||
* Woah!
|
||||
*/
|
||||
export async function GET() {
|
||||
const tiers = await api.tiers();
|
||||
return new Response(Tiers.encode(tiers).finish());
|
||||
}
|
||||
Reference in new issue
Block a user