From 13faad09772a733c7f1abbf1e83ac2fd9272a1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 1 Sep 2024 18:00:15 -0500 Subject: [PATCH] feat: swap button --- .../[id]/components/Model/HeroSection.tsx | 19 +++---- .../components/Model/MetaSection/index.tsx | 50 +++++++++++++++++-- src/app/tools/tankopedia/[id]/page.tsx | 43 +++++++++------- 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx index dabd5380c..0961f5022 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/HeroSection.tsx @@ -12,11 +12,7 @@ import { TankSandbox } from './TankSandbox'; import { TankSandboxLoader } from './TankSandboxLoader'; import { Options } from './components/Options'; -interface HeroSectionProps { - id: number; -} - -export function HeroSection({ id }: HeroSectionProps) { +export function HeroSection() { const canvas = useRef(null); const isFullScreen = useFullScreen(); const protagonist = Duel.use((state) => state.protagonist.tank); @@ -29,10 +25,11 @@ export function HeroSection({ id }: HeroSectionProps) { ? 'amber' : undefined; const awaitedTankDefinitions = use(tankDefinitions); - const tank = awaitedTankDefinitions[id]; const thicknessRange = useMemo(() => { const entries = Object.values(awaitedTankDefinitions); - const filtered = entries.filter((thisTank) => thisTank.tier === tank.tier); + const filtered = entries.filter( + (thisTank) => thisTank.tier === protagonist.tier, + ); const value = (filtered.reduce((accumulator, thisTank) => { return ( @@ -46,7 +43,7 @@ export function HeroSection({ id }: HeroSectionProps) { (3 / 4); return { value } satisfies ThicknessRange; - }, [tank.tier]); + }, [protagonist]); useEffect(() => { setDummyLoader(false); @@ -90,7 +87,7 @@ export function HeroSection({ id }: HeroSectionProps) { > - {tank.name} + {protagonist.name} @@ -114,14 +111,14 @@ export function HeroSection({ id }: HeroSectionProps) { } diff --git a/src/app/tools/tankopedia/[id]/components/Model/MetaSection/index.tsx b/src/app/tools/tankopedia/[id]/components/Model/MetaSection/index.tsx index 9911023cf..0ebee785a 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/MetaSection/index.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/MetaSection/index.tsx @@ -1,11 +1,17 @@ -import { ChevronLeftIcon, MixIcon } from '@radix-ui/react-icons'; -import { Button, Code, Flex } from '@radix-ui/themes'; +import { ChevronLeftIcon, MixIcon, UpdateIcon } from '@radix-ui/react-icons'; +import { Button, Code, Dialog, Flex } from '@radix-ui/themes'; +import { use, useState } from 'react'; import { classIcons } from '../../../../../../../components/ClassIcon'; import { Link } from '../../../../../../../components/Link'; import { asset } from '../../../../../../../core/blitzkit/asset'; +import { modelDefinitions } from '../../../../../../../core/blitzkit/modelDefinitions'; +import { provisionDefinitions } from '../../../../../../../core/blitzkit/provisionDefinitions'; +import { tankToDuelMember } from '../../../../../../../core/blitzkit/tankToDuelMember'; import strings from '../../../../../../../lang/en-US.json'; import * as App from '../../../../../../../stores/app'; import * as Duel from '../../../../../../../stores/duel'; +import * as TankopediaEphemeral from '../../../../../../../stores/tankopediaEphemeral'; +import { TankSearch } from '../../../../components/TankSearch'; import { Listing } from './components/Listing'; import { Votes } from './components/Votes'; @@ -18,6 +24,11 @@ export function MetaSection() { protagonist.id === antagonist.id ? [protagonist.id] : [protagonist.id, antagonist.id]; + const mutateDuel = Duel.useMutation(); + const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation(); + const awaitedProvisionDefinitions = use(provisionDefinitions); + const [showSwapDialog, setShowSwapDialog] = useState(false); + const awaitedModelDefinitions = use(modelDefinitions); return ( @@ -31,11 +42,44 @@ export function MetaSection() { - + + + + + + + + { + setShowSwapDialog(false); + mutateTankopediaEphemeral((draft) => { + draft.model = awaitedModelDefinitions[tank.id]; + }); + mutateDuel((draft) => { + draft.protagonist = tankToDuelMember( + tank, + awaitedProvisionDefinitions, + ); + }); + + window.history.replaceState( + null, + '', + `/tools/tankopedia/${tank.id}`, + ); + }} + /> + + state.protagonist.tank); + const title = `${tank.name} - Tier ${TIER_ROMAN_NUMERALS[tank.tier]} ${ + (strings.common.nations_adjectives as Record)[tank.nation] + } ${strings.common.tank_class_short[tank.class]}`; useEffect(() => { function handleKeyDown(event: KeyboardEvent) { @@ -79,20 +85,23 @@ export default function Page({ params }: { params: { id: string } }) { }, []); return ( - - - - - {/* */} - {/* */} - - {!exempt && } - - {!exempt && } - - - - {!exempt && } - + <> + {title} + + + + + + + {!exempt && } + + + {!exempt && } + + + + {!exempt && } + + ); }