feat: custom components

This commit is contained in:
TrèsAbhi committed 2025-05-27 12:39:04 -05:00
1 parent bc6bb4f10e
commit 69b13fd33a
9 files changed
+164 -58

No files matched your search

@@ -1,9 +1,20 @@
import { use } from 'react';
import {
LocaleProvider,
useLocale,
type LocaleAcceptorProps,
} from '../hooks/useLocale';
export function TestComponent() {
const content = use(
fetch('https://example.com/').then((response) => response.text()),
);
function Content() {
const { locale, strings } = useLocale();
const content = JSON.stringify(strings, null, 2);
return <pre children={content} />;
return <span>{strings.common.units.deg_s}</span>;
}
export function TestComponent({ locale }: LocaleAcceptorProps) {
return (
<LocaleProvider locale={locale}>
<Content />
</LocaleProvider>
);
}
@@ -6,4 +6,4 @@ export const unpackedMetadata = new UnpackedMetadataAccessor(
await requestAutoProxyClient<GetPackedMetadataAsyncResponse>(
'GetPackedMetadataAsyncRequest',
).then(unpackMetadata),
);
).injectBlitzkit();
+6 -4
View File
@@ -23,15 +23,17 @@ export function LocaleProvider({ locale, children }: LocaleProviderProps) {
);
}
const strings = import.meta.glob('../../../i18n/strings/*.json', {
import: 'default',
});
const cache = new Map<string, Promise<BlitzKitStrings>>();
function loadLocale(locale: string) {
if (cache.has(locale)) return cache.get(locale)!;
const promise = fetch(`/api/strings/${locale}.json`).then((response) => {
if (!response.ok) throw new Error('Failed to load locale');
return response.json();
});
const promise = strings[
`../../../i18n/strings/${locale}.json`
]() as Promise<BlitzKitStrings>;
cache.set(locale, promise);
@@ -1,6 +1,6 @@
---
import { CatalogItemsComponent } from '@protos/blitz_static_catalog_items_group_component';
import { TestComponent } from '../../../components/TestComponent';
import { BlitzKitAllTankEntities } from '@protos/blitzkit_static_all_tank_entities';
import { unpackedMetadata } from '../../../core/blitz/unpackedMetadata';
export { getStaticPaths } from '../index.astro';
@@ -9,6 +9,15 @@ const { locale } = Astro.props;
const allTanks = unpackedMetadata
.get('CatalogItemsGroupEntity.all_tanks')
.get(CatalogItemsComponent, 'catalogItemsGroupComponent');
const allTankEntities = unpackedMetadata
.get('BlitzKitAllTankEntities.all_tanks')
.get(BlitzKitAllTankEntities, 'blitzkitAllTankEntitiesComponent');
---
<TestComponent />
<pre>
{JSON.stringify(allTankEntities.tanks.map(tank=>({
tank: tank.catalog_id,
components: tank.components.map(component=>component.key)
})), null, 2)}
</pre>
@@ -1,14 +0,0 @@
import locales from '@blitzkit/i18n/locales.json' with { type: 'json' };
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
import { getStrings } from 'packages/website-ue/src/core/i18n/getStrings';
export const getStaticPaths: GetStaticPaths = () => {
return locales.supported.map(
({ locale }) => ({ params: { locale } }) satisfies GetStaticPathsItem,
);
};
export const GET: APIRoute = async ({ params, request }) => {
const strings = await getStrings(params.locale!);
return Response.json(strings);
};