diff --git a/src/app/tools/tankopedia/[id]/layout.tsx b/src/app/tools/tankopedia/[id]/layout.tsx index a7379f6c6..bdf20e7bc 100644 --- a/src/app/tools/tankopedia/[id]/layout.tsx +++ b/src/app/tools/tankopedia/[id]/layout.tsx @@ -5,15 +5,13 @@ import { tankIcon } from '../../../../core/blitzkit/tankIcon'; import strings from '../../../../lang/en-US.json'; import * as Duel from '../../../../stores/duel'; -interface TankopediaLayoutProps { - children: ReactNode; - params: { id: string }; -} - -export default async function TankopediaLayout({ +export default async function Layout({ children, params, -}: TankopediaLayoutProps) { +}: { + children: ReactNode; + params: { id: string }; +}) { const id = Number(params.id); const awaitedTankDefinitions = await tankDefinitions; const tank = awaitedTankDefinitions[id]; @@ -23,7 +21,7 @@ export default async function TankopediaLayout({ const description = `Statistics, armor profiles, and equipment for ${tank.name}`; return ( - + {title} diff --git a/src/app/tools/tankopedia/[id]/page.tsx b/src/app/tools/tankopedia/[id]/page.tsx index 09eb0f310..9f8a5195c 100644 --- a/src/app/tools/tankopedia/[id]/page.tsx +++ b/src/app/tools/tankopedia/[id]/page.tsx @@ -13,8 +13,7 @@ import { TechTreeSection } from './components/Model/TechTreeSection'; import { ShotDisplaySection } from './components/ShotDisplaySection'; import { VideoSection } from './components/VideoSection'; -// TODO: remove this param if not needed for duel assignment -export default function Page({ params }: { params: { id: string } }) { +export default function Page() { const exempt = useAdExempt(); const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation(); const mutateDuel = Duel.useMutation(); diff --git a/src/core/zustand/createNextSafeStore.tsx b/src/core/zustand/createNextSafeStore.tsx index 04e521fa3..0b7eb8762 100644 --- a/src/core/zustand/createNextSafeStore.tsx +++ b/src/core/zustand/createNextSafeStore.tsx @@ -1,5 +1,4 @@ import { Draft, produce } from 'immer'; -import { usePathname } from 'next/navigation'; import { createContext, ReactNode, @@ -10,9 +9,9 @@ import { } from 'react'; import { StoreApi, useStore as useStoreZustand } from 'zustand'; -interface StoreProviderProps { +type StoreProviderProps = { children: ReactNode; -} +} & (InitData extends unknown ? { data?: InitData } : { data: InitData }); // idk why zustand doesn't export this type ExtractState = S extends { @@ -21,27 +20,26 @@ type ExtractState = S extends { ? T : never; -interface InitialContext { - pathName: string; -} - -export function createNextSafeStore>( - initial: (context: InitialContext) => Store | Promise, +export function createNextSafeStore, InitData>( + initialize: (data: InitData) => Store | Promise, ) { type Type = Store extends StoreApi ? T : never; const Context = createContext(undefined); - function Provider({ children }: StoreProviderProps) { - const pathName = usePathname(); + function Provider(props: StoreProviderProps) { const storeRef = useRef(); - const context = { pathName }; - const storePromise = useMemo(async () => await initial(context), []); + const storePromise = useMemo( + async () => await initialize((props as { data: InitData }).data), + [], + ); const awaitedStore = useReact(storePromise); if (!storeRef.current) storeRef.current = awaitedStore; return ( - {children} + + {props.children} + ); } diff --git a/src/stores/duel/index.ts b/src/stores/duel/index.ts index 278a4cc3c..fc90294e4 100644 --- a/src/stores/duel/index.ts +++ b/src/stores/duel/index.ts @@ -50,8 +50,7 @@ export interface Duel { } export const { Provider, use, useMutation, useStore } = createNextSafeStore( - async ({ pathName }) => { - const id = Number(pathName.split('/')[3]); + async (id: number) => { const awaitedTankDefinitions = await tankDefinitions; const awaitedProvisionDefinitions = await provisionDefinitions; const tank = awaitedTankDefinitions[id];