mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: name fetching
This commit is contained in:
1 parent
18d762c41b
commit
35894f39cf
5 files changed
+144
-63
No files matched your search
@@ -46,5 +46,6 @@ export * from './votes';
|
|||||||
export * from './createDefaultProvisions';
|
export * from './createDefaultProvisions';
|
||||||
export * from './metaSortTank';
|
export * from './metaSortTank';
|
||||||
export * from './romanize';
|
export * from './romanize';
|
||||||
|
export * from './tank';
|
||||||
export * from './tanks';
|
export * from './tanks';
|
||||||
export * from './youtubers';
|
export * from './youtubers';
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { fetchPB } from '../protobuf';
|
||||||
|
import { Tank } from '../protos';
|
||||||
|
import { asset } from './asset';
|
||||||
|
|
||||||
|
export function fetchTank(id: string) {
|
||||||
|
return fetchPB(asset(`tanks/${id}/meta.pb`), Tank);
|
||||||
|
}
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
// source: packages/core/src/protos/i18n.proto
|
// source: packages/core/src/protos/i18n.proto
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
|
||||||
|
|
||||||
export const protobufPackage = "blitzkit";
|
export const protobufPackage = 'blitzkit';
|
||||||
|
|
||||||
export interface I18n {
|
export interface I18n {
|
||||||
locales: { [key: string]: string };
|
locales: { [key: string]: string };
|
||||||
@@ -18,20 +18,27 @@ export interface I18n_LocalesEntry {
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBaseI18n(): I18n {
|
export function createBaseI18n(): I18n {
|
||||||
return { locales: {} };
|
return { locales: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const I18n: MessageFns<I18n> = {
|
export const I18n: MessageFns<I18n> = {
|
||||||
encode(message: I18n, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
encode(
|
||||||
|
message: I18n,
|
||||||
|
writer: BinaryWriter = new BinaryWriter(),
|
||||||
|
): BinaryWriter {
|
||||||
Object.entries(message.locales).forEach(([key, value]) => {
|
Object.entries(message.locales).forEach(([key, value]) => {
|
||||||
I18n_LocalesEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join();
|
I18n_LocalesEntry.encode(
|
||||||
|
{ key: key as any, value },
|
||||||
|
writer.uint32(10).fork(),
|
||||||
|
).join();
|
||||||
});
|
});
|
||||||
return writer;
|
return writer;
|
||||||
},
|
},
|
||||||
|
|
||||||
decode(input: BinaryReader | Uint8Array, length?: number): I18n {
|
decode(input: BinaryReader | Uint8Array, length?: number): I18n {
|
||||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
const reader =
|
||||||
|
input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
let end = length === undefined ? reader.len : reader.pos + length;
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
const message = createBaseI18n();
|
const message = createBaseI18n();
|
||||||
while (reader.pos < end) {
|
while (reader.pos < end) {
|
||||||
@@ -60,10 +67,13 @@ export const I18n: MessageFns<I18n> = {
|
|||||||
fromJSON(object: any): I18n {
|
fromJSON(object: any): I18n {
|
||||||
return {
|
return {
|
||||||
locales: isObject(object.locales)
|
locales: isObject(object.locales)
|
||||||
? Object.entries(object.locales).reduce<{ [key: string]: string }>((acc, [key, value]) => {
|
? Object.entries(object.locales).reduce<{ [key: string]: string }>(
|
||||||
acc[key] = String(value);
|
(acc, [key, value]) => {
|
||||||
return acc;
|
acc[key] = String(value);
|
||||||
}, {})
|
return acc;
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
)
|
||||||
: {},
|
: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -87,7 +97,9 @@ export const I18n: MessageFns<I18n> = {
|
|||||||
},
|
},
|
||||||
fromPartial<I extends Exact<DeepPartial<I18n>, I>>(object: I): I18n {
|
fromPartial<I extends Exact<DeepPartial<I18n>, I>>(object: I): I18n {
|
||||||
const message = createBaseI18n();
|
const message = createBaseI18n();
|
||||||
message.locales = Object.entries(object.locales ?? {}).reduce<{ [key: string]: string }>((acc, [key, value]) => {
|
message.locales = Object.entries(object.locales ?? {}).reduce<{
|
||||||
|
[key: string]: string;
|
||||||
|
}>((acc, [key, value]) => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
acc[key] = globalThis.String(value);
|
acc[key] = globalThis.String(value);
|
||||||
}
|
}
|
||||||
@@ -98,11 +110,14 @@ export const I18n: MessageFns<I18n> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function createBaseI18n_LocalesEntry(): I18n_LocalesEntry {
|
function createBaseI18n_LocalesEntry(): I18n_LocalesEntry {
|
||||||
return { key: "", value: "" };
|
return { key: '', value: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const I18n_LocalesEntry: MessageFns<I18n_LocalesEntry> = {
|
export const I18n_LocalesEntry: MessageFns<I18n_LocalesEntry> = {
|
||||||
encode(message: I18n_LocalesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
encode(
|
||||||
|
message: I18n_LocalesEntry,
|
||||||
|
writer: BinaryWriter = new BinaryWriter(),
|
||||||
|
): BinaryWriter {
|
||||||
if (message.key !== undefined) {
|
if (message.key !== undefined) {
|
||||||
writer.uint32(10).string(message.key);
|
writer.uint32(10).string(message.key);
|
||||||
}
|
}
|
||||||
@@ -113,7 +128,8 @@ export const I18n_LocalesEntry: MessageFns<I18n_LocalesEntry> = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
decode(input: BinaryReader | Uint8Array, length?: number): I18n_LocalesEntry {
|
decode(input: BinaryReader | Uint8Array, length?: number): I18n_LocalesEntry {
|
||||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
const reader =
|
||||||
|
input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
let end = length === undefined ? reader.len : reader.pos + length;
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
const message = createBaseI18n_LocalesEntry();
|
const message = createBaseI18n_LocalesEntry();
|
||||||
while (reader.pos < end) {
|
while (reader.pos < end) {
|
||||||
@@ -146,8 +162,10 @@ export const I18n_LocalesEntry: MessageFns<I18n_LocalesEntry> = {
|
|||||||
|
|
||||||
fromJSON(object: any): I18n_LocalesEntry {
|
fromJSON(object: any): I18n_LocalesEntry {
|
||||||
return {
|
return {
|
||||||
key: globalThis.String(assertSet("I18n_LocalesEntry.key", object.key)),
|
key: globalThis.String(assertSet('I18n_LocalesEntry.key', object.key)),
|
||||||
value: globalThis.String(assertSet("I18n_LocalesEntry.value", object.value)),
|
value: globalThis.String(
|
||||||
|
assertSet('I18n_LocalesEntry.value', object.value),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -162,32 +180,51 @@ export const I18n_LocalesEntry: MessageFns<I18n_LocalesEntry> = {
|
|||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
create<I extends Exact<DeepPartial<I18n_LocalesEntry>, I>>(base?: I): I18n_LocalesEntry {
|
create<I extends Exact<DeepPartial<I18n_LocalesEntry>, I>>(
|
||||||
|
base?: I,
|
||||||
|
): I18n_LocalesEntry {
|
||||||
return I18n_LocalesEntry.fromPartial(base ?? ({} as any));
|
return I18n_LocalesEntry.fromPartial(base ?? ({} as any));
|
||||||
},
|
},
|
||||||
fromPartial<I extends Exact<DeepPartial<I18n_LocalesEntry>, I>>(object: I): I18n_LocalesEntry {
|
fromPartial<I extends Exact<DeepPartial<I18n_LocalesEntry>, I>>(
|
||||||
|
object: I,
|
||||||
|
): I18n_LocalesEntry {
|
||||||
const message = createBaseI18n_LocalesEntry();
|
const message = createBaseI18n_LocalesEntry();
|
||||||
message.key = object.key ?? "";
|
message.key = object.key ?? '';
|
||||||
message.value = object.value ?? "";
|
message.value = object.value ?? '';
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
type Builtin =
|
||||||
|
| Date
|
||||||
|
| Function
|
||||||
|
| Uint8Array
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| undefined;
|
||||||
|
|
||||||
export type DeepPartial<T> = T extends Builtin ? T
|
export type DeepPartial<T> = T extends Builtin
|
||||||
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
? T
|
||||||
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
: T extends globalThis.Array<infer U>
|
||||||
: T extends { $case: string; value: unknown } ? { $case: T["$case"]; value?: DeepPartial<T["value"]> }
|
? globalThis.Array<DeepPartial<U>>
|
||||||
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
: T extends ReadonlyArray<infer U>
|
||||||
: Partial<T>;
|
? ReadonlyArray<DeepPartial<U>>
|
||||||
|
: T extends { $case: string; value: unknown }
|
||||||
|
? { $case: T['$case']; value?: DeepPartial<T['value']> }
|
||||||
|
: T extends {}
|
||||||
|
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||||
|
: Partial<T>;
|
||||||
|
|
||||||
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||||
export type Exact<P, I extends P> = P extends Builtin ? P
|
export type Exact<P, I extends P> = P extends Builtin
|
||||||
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
? P
|
||||||
|
: P & { [K in keyof P]: Exact<P[K], I[K]> } & {
|
||||||
|
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
||||||
|
};
|
||||||
|
|
||||||
function isObject(value: any): boolean {
|
function isObject(value: any): boolean {
|
||||||
return typeof value === "object" && value !== null;
|
return typeof value === 'object' && value !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSet(value: any): boolean {
|
function isSet(value: any): boolean {
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
// source: packages/core/src/protos/tank.proto
|
// source: packages/core/src/protos/tank.proto
|
||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
|
||||||
import { I18n } from "./i18n";
|
import { I18n, createBaseI18n } from './i18n';
|
||||||
|
|
||||||
export const protobufPackage = "blitzkit";
|
export const protobufPackage = 'blitzkit';
|
||||||
|
|
||||||
export interface Tank {
|
export interface Tank {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -17,15 +17,18 @@ export interface Tank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createBaseTank(): Tank {
|
function createBaseTank(): Tank {
|
||||||
return { id: "", slug: "", name: createBaseI18n() };
|
return { id: '', slug: '', name: createBaseI18n() };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Tank: MessageFns<Tank> = {
|
export const Tank: MessageFns<Tank> = {
|
||||||
encode(message: Tank, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
encode(
|
||||||
if (message.id !== "") {
|
message: Tank,
|
||||||
|
writer: BinaryWriter = new BinaryWriter(),
|
||||||
|
): BinaryWriter {
|
||||||
|
if (message.id !== '') {
|
||||||
writer.uint32(10).string(message.id);
|
writer.uint32(10).string(message.id);
|
||||||
}
|
}
|
||||||
if (message.slug !== "") {
|
if (message.slug !== '') {
|
||||||
writer.uint32(18).string(message.slug);
|
writer.uint32(18).string(message.slug);
|
||||||
}
|
}
|
||||||
if (message.name !== undefined) {
|
if (message.name !== undefined) {
|
||||||
@@ -35,7 +38,8 @@ export const Tank: MessageFns<Tank> = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
decode(input: BinaryReader | Uint8Array, length?: number): Tank {
|
decode(input: BinaryReader | Uint8Array, length?: number): Tank {
|
||||||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
const reader =
|
||||||
|
input instanceof BinaryReader ? input : new BinaryReader(input);
|
||||||
let end = length === undefined ? reader.len : reader.pos + length;
|
let end = length === undefined ? reader.len : reader.pos + length;
|
||||||
const message = createBaseTank();
|
const message = createBaseTank();
|
||||||
while (reader.pos < end) {
|
while (reader.pos < end) {
|
||||||
@@ -76,18 +80,18 @@ export const Tank: MessageFns<Tank> = {
|
|||||||
|
|
||||||
fromJSON(object: any): Tank {
|
fromJSON(object: any): Tank {
|
||||||
return {
|
return {
|
||||||
id: globalThis.String(assertSet("Tank.id", object.id)),
|
id: globalThis.String(assertSet('Tank.id', object.id)),
|
||||||
slug: globalThis.String(assertSet("Tank.slug", object.slug)),
|
slug: globalThis.String(assertSet('Tank.slug', object.slug)),
|
||||||
name: I18n.fromJSON(assertSet("Tank.name", object.name)),
|
name: I18n.fromJSON(assertSet('Tank.name', object.name)),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
toJSON(message: Tank): unknown {
|
toJSON(message: Tank): unknown {
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
if (message.id !== "") {
|
if (message.id !== '') {
|
||||||
obj.id = message.id;
|
obj.id = message.id;
|
||||||
}
|
}
|
||||||
if (message.slug !== "") {
|
if (message.slug !== '') {
|
||||||
obj.slug = message.slug;
|
obj.slug = message.slug;
|
||||||
}
|
}
|
||||||
if (message.name !== undefined) {
|
if (message.name !== undefined) {
|
||||||
@@ -101,27 +105,43 @@ export const Tank: MessageFns<Tank> = {
|
|||||||
},
|
},
|
||||||
fromPartial<I extends Exact<DeepPartial<Tank>, I>>(object: I): Tank {
|
fromPartial<I extends Exact<DeepPartial<Tank>, I>>(object: I): Tank {
|
||||||
const message = createBaseTank();
|
const message = createBaseTank();
|
||||||
message.id = object.id ?? "";
|
message.id = object.id ?? '';
|
||||||
message.slug = object.slug ?? "";
|
message.slug = object.slug ?? '';
|
||||||
message.name = (object.name !== undefined && object.name !== null)
|
message.name =
|
||||||
? I18n.fromPartial(object.name)
|
object.name !== undefined && object.name !== null
|
||||||
: createBaseI18n();
|
? I18n.fromPartial(object.name)
|
||||||
|
: createBaseI18n();
|
||||||
return message;
|
return message;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
type Builtin =
|
||||||
|
| Date
|
||||||
|
| Function
|
||||||
|
| Uint8Array
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| undefined;
|
||||||
|
|
||||||
export type DeepPartial<T> = T extends Builtin ? T
|
export type DeepPartial<T> = T extends Builtin
|
||||||
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
|
? T
|
||||||
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
|
: T extends globalThis.Array<infer U>
|
||||||
: T extends { $case: string; value: unknown } ? { $case: T["$case"]; value?: DeepPartial<T["value"]> }
|
? globalThis.Array<DeepPartial<U>>
|
||||||
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
|
: T extends ReadonlyArray<infer U>
|
||||||
: Partial<T>;
|
? ReadonlyArray<DeepPartial<U>>
|
||||||
|
: T extends { $case: string; value: unknown }
|
||||||
|
? { $case: T['$case']; value?: DeepPartial<T['value']> }
|
||||||
|
: T extends {}
|
||||||
|
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||||
|
: Partial<T>;
|
||||||
|
|
||||||
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
||||||
export type Exact<P, I extends P> = P extends Builtin ? P
|
export type Exact<P, I extends P> = P extends Builtin
|
||||||
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
|
? P
|
||||||
|
: P & { [K in keyof P]: Exact<P[K], I[K]> } & {
|
||||||
|
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
||||||
|
};
|
||||||
|
|
||||||
function isSet(value: any): boolean {
|
function isSet(value: any): boolean {
|
||||||
return value !== null && value !== undefined;
|
return value !== null && value !== undefined;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
import { asset, fetchTank } from '@blitzkit/core';
|
||||||
|
import { Box, Flex, Text } from '@radix-ui/themes';
|
||||||
import { LinkI18n } from '../../../components/LinkI18n';
|
import { LinkI18n } from '../../../components/LinkI18n';
|
||||||
import { PageWrapper } from '../../../components/PageWrapper';
|
import { PageWrapper } from '../../../components/PageWrapper';
|
||||||
import { tanksTool } from '../../../constants/tools';
|
import { tanksTool } from '../../../constants/tools';
|
||||||
@@ -10,18 +12,32 @@ export { getStaticPaths } from '../index.astro';
|
|||||||
const locale = Astro.params.locale;
|
const locale = Astro.params.locale;
|
||||||
|
|
||||||
const tanks = await awaitableTanks;
|
const tanks = await awaitableTanks;
|
||||||
|
const fullTanks = await Promise.all(tanks.tanks.map(({ id }) => fetchTank(id)));
|
||||||
---
|
---
|
||||||
|
|
||||||
<ToolLayout tool={tanksTool}>
|
<ToolLayout tool={tanksTool}>
|
||||||
<PageWrapper>
|
<PageWrapper>
|
||||||
{
|
{
|
||||||
tanks.tanks
|
fullTanks
|
||||||
.sort((a, b) => a.slug.localeCompare(b.slug))
|
.sort((a, b) => a.slug.localeCompare(b.slug))
|
||||||
.map((tank) => (
|
.map((tank) => {
|
||||||
<LinkI18n {locale} href={`/tanks/${tank.slug}`}>
|
return (
|
||||||
{tank.slug}
|
<LinkI18n {locale} href={`/tanks/${tank.slug}`}>
|
||||||
</LinkI18n>
|
<Flex align="center" gap="2">
|
||||||
))
|
<Box
|
||||||
|
width="8rem"
|
||||||
|
height="6rem"
|
||||||
|
style={{
|
||||||
|
backgroundImage: `url(${asset(`tanks/${tank.id}/icons/big.png`)})`,
|
||||||
|
backgroundSize: '150%',
|
||||||
|
backgroundPosition: 'center',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Text>{tank.name.locales.en}</Text>
|
||||||
|
</Flex>
|
||||||
|
</LinkI18n>
|
||||||
|
);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
</ToolLayout>
|
</ToolLayout>
|
||||||
Reference in new issue
Block a user