mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: optimize tankList
This commit is contained in:
1 parent
fcfc97b964
commit
385d165512
3 files changed
+12
-9
No files matched your search
@@ -3,7 +3,7 @@ import { sluggify } from "@blitzkit/core";
|
||||
import type { RemoteStorageComponent } from "@protos/blitz_static_remote_storage_component";
|
||||
import { parse } from "yaml";
|
||||
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 { AbstractAPI } from "./abstract";
|
||||
|
||||
@@ -120,15 +120,13 @@ export class ServerAPI extends AbstractAPI {
|
||||
const data: Tanks = { tanks: {} };
|
||||
|
||||
for (const { id } of tankList.list) {
|
||||
console.log(id);
|
||||
data.tanks[id] = await this.tank(id);
|
||||
data.tanks[id] = await this._tank(id, tankList);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async tank(id: string) {
|
||||
const tankList = await this.tankList();
|
||||
async _tank(id: string, tankList: TankList) {
|
||||
const tankListEntry = tankList.list.find((tank) => tank.id === id);
|
||||
|
||||
if (!tankListEntry) {
|
||||
@@ -142,4 +140,9 @@ export class ServerAPI extends AbstractAPI {
|
||||
|
||||
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";
|
||||
|
||||
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 },
|
||||
props: { id: tank.id },
|
||||
}));
|
||||
|
||||
@@ -3,14 +3,14 @@ import "@radix-ui/colors/violet-dark.css";
|
||||
import { api } from "../../core/api/dynamic";
|
||||
import BaseLayout from "../../layouts/BaseLayout.astro";
|
||||
|
||||
const tanksList = await api.tanks();
|
||||
const tankList = await api.tankList();
|
||||
---
|
||||
|
||||
<BaseLayout accent="violet">
|
||||
<h1>tanks</h1>
|
||||
|
||||
{
|
||||
tanksList.tanks.map(({ id, slug }) => (
|
||||
tankList.list.map(({ id, slug }) => (
|
||||
<p>
|
||||
<a href={`/tanks/${slug}`}>
|
||||
{slug} ({id})
|
||||
|
||||
Reference in new issue
Block a user