From 2c2e93649c7501cc052fabd210e38a13727fbfa1 Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Thu, 26 Jun 2025 14:39:04 -0400 Subject: [PATCH] cleanup --- app/AppContext.tsx | 5 ++--- components/Card.tsx | 23 ++++++++++++----------- components/TarokkaGrid.tsx | 6 ++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/AppContext.tsx b/app/AppContext.tsx index 6f2a99a..8adf56c 100644 --- a/app/AppContext.tsx +++ b/app/AppContext.tsx @@ -33,10 +33,11 @@ export interface AppContext { } export function AppProvider({ children }: { children: ReactNode }) { + const [gameData, setGameData] = useState(gameStart); const [gameID, setGameID] = useState(''); const [noGame, setNoGame] = useState(false); const [selectCardIndex, setSelectCardIndex] = useState(-1); - const [gameData, setGameData] = useState(gameStart); + const [tilts, setTilts] = useState([]); const { flipCard, redraw, select, handleSettings } = useSocket({ gameID, @@ -44,8 +45,6 @@ export function AppProvider({ children }: { children: ReactNode }) { setNoGame, }); - const [tilts, setTilts] = useState([]); - const handleSelect = (cardID: string) => { setSelectCardIndex(-1); diff --git a/components/Card.tsx b/components/Card.tsx index 663739c..57c11f8 100644 --- a/components/Card.tsx +++ b/components/Card.tsx @@ -11,32 +11,33 @@ import getURL from '@/tools/getURL'; import tarokkaCards from '@/constants/tarokkaCards'; import { layout } from '@/constants/tarokka'; -import { Settings, TarokkaGameCard } from '@/types'; +import { TarokkaGameCard } from '@/types'; const cardBack = tarokkaCards.find((card) => card.back)!; type CardProps = { - dm: boolean; card: TarokkaGameCard; cardIndex: number; - settings: Settings; }; -export default function Card({ dm, card, cardIndex, settings }: CardProps) { +export default function Card({ card, cardIndex }: CardProps) { const [tooltip, setTooltip] = useState(null); - const { flipCard, redraw, setSelectCardIndex } = useAppContext(); + const { flipCard, gameData, redraw, setSelectCardIndex } = useAppContext(); + + const { dmID, settings } = gameData; + const isDM = !!dmID; const { aria, flipped } = card; const position = layout[cardIndex]; const handleClick = () => { - if (dm) { + if (isDM) { flipCard(cardIndex); } }; const getTooltip = () => { - const text = getCardInfo(card, position, dm, settings); + const text = getCardInfo(card, position, isDM, settings); return text.length ? ( <> @@ -53,7 +54,7 @@ export default function Card({ dm, card, cardIndex, settings }: CardProps) { return (
- {dm && ( + {isDM && ( <> {aria} Card Back - {dm && !flipped && ( + {isDM && !flipped && ( redraw(cardIndex)} onSelect={() => setSelectCardIndex(cardIndex)} diff --git a/components/TarokkaGrid.tsx b/components/TarokkaGrid.tsx index 089b149..2b06deb 100644 --- a/components/TarokkaGrid.tsx +++ b/components/TarokkaGrid.tsx @@ -7,9 +7,7 @@ import type {} from '@/types'; export default function TarokkaGrid() { const { gameData } = useAppContext(); - - const { dmID, cards, settings } = gameData; - const isDM = !!dmID; + const { cards } = gameData; // map our five Tarokka cards to their proper locations in a 3x3 grid // common deck cards: left, top, and right @@ -22,7 +20,7 @@ export default function TarokkaGrid() { .map(arrangeCards) .map((card, index) => (
- {card && } + {card && }
))}