feat: optimize tankList

This commit is contained in:
TrèsAbhi committed 2025-12-26 19:21:14 -06:00
1 parent fcfc97b964
commit 385d165512
3 files changed
+12 -9

No files matched your search

+8 -5
View File
@@ -3,7 +3,7 @@ import { sluggify } from "@blitzkit/core";
import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component"; import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component";
import { parse } from "yaml"; import { parse } from "yaml";
import type { Tank } from "../../protos/tank"; import type { Tank } from "../../protos/tank";
import type { TankListEntry } from "../../protos/tank_list"; import type { TankList, TankListEntry } from "../../protos/tank_list";
import type { Tanks } from "../../protos/tanks"; import type { Tanks } from "../../protos/tanks";
import { AbstractAPI } from "./abstract"; import { AbstractAPI } from "./abstract";
@@ -120,15 +120,13 @@ export class ServerAPI extends AbstractAPI {
const data: Tanks = { tanks: {} }; const data: Tanks = { tanks: {} };
for (const { id } of tankList.list) { for (const { id } of tankList.list) {
console.log(id); data.tanks[id] = await this._tank(id, tankList);
data.tanks[id] = await this.tank(id);
} }
return data; return data;
} }
async tank(id: string) { async _tank(id: string, tankList: TankList) {
const tankList = await this.tankList();
const tankListEntry = tankList.list.find((tank) => tank.id === id); const tankListEntry = tankList.list.find((tank) => tank.id === id);
if (!tankListEntry) { if (!tankListEntry) {
@@ -142,4 +140,9 @@ export class ServerAPI extends AbstractAPI {
return { tank, compensation, slug } satisfies Tank; return { tank, compensation, slug } satisfies Tank;
} }
async tank(id: string) {
const tankList = await this.tankList();
return this._tank(id, tankList);
}
} }
@@ -6,9 +6,9 @@ import BaseLayout from "../../../layouts/BaseLayout.astro";
import { Page } from "./_index"; import { Page } from "./_index";
export const getStaticPaths = (async () => { export const getStaticPaths = (async () => {
const { tanks } = await api.tanks(); const { list } = await api.tankList();
return tanks.map((tank) => ({ return list.map((tank) => ({
params: { slug: tank.slug }, params: { slug: tank.slug },
props: { id: tank.id }, props: { id: tank.id },
})); }));
@@ -3,14 +3,14 @@ import "@radix-ui/colors/violet-dark.css";
import { api } from "../../core/api/dynamic"; import { api } from "../../core/api/dynamic";
import BaseLayout from "../../layouts/BaseLayout.astro"; import BaseLayout from "../../layouts/BaseLayout.astro";
const tanksList = await api.tanks(); const tankList = await api.tankList();
--- ---
<BaseLayout accent="violet"> <BaseLayout accent="violet">
<h1>tanks</h1> <h1>tanks</h1>
{ {
tanksList.tanks.map(({ id, slug }) => ( tankList.list.map(({ id, slug }) => (
<p> <p>
<a href={`/tanks/${slug}`}> <a href={`/tanks/${slug}`}>
{slug} ({id}) {slug} ({id})