refactoring
This commit is contained in:
@@ -5,19 +5,17 @@ import { useParams } from 'next/navigation';
|
||||
import { useAppContext } from '@/app/AppContext';
|
||||
import { Eye } from 'lucide-react';
|
||||
|
||||
import Card from '@/components/Card';
|
||||
import CardSelect from '@/components/CardSelect';
|
||||
import CopyButton from '@/components/CopyButton';
|
||||
import Notes from '@/components/Notes';
|
||||
import NotFound from '@/components/NotFound';
|
||||
import Settings from '@/components/Settings';
|
||||
import CardSelect from '@/components/CardSelect';
|
||||
|
||||
import { cardMap, layout } from '@/constants/tarokka';
|
||||
import TarokkaGrid from '@/components/TarokkaGrid';
|
||||
|
||||
import type { Deck } from '@/types';
|
||||
|
||||
export default function GamePage() {
|
||||
const { gameData, noGame, flipCard, handleSettings, redraw, select, setGameID } = useAppContext();
|
||||
const { gameData, noGame, handleSettings, select, setGameID } = useAppContext();
|
||||
const { gameID } = useParams();
|
||||
|
||||
const [selectCard, setSelectCard] = useState(-1);
|
||||
@@ -32,17 +30,6 @@ export default function GamePage() {
|
||||
}
|
||||
}, [gameID]);
|
||||
|
||||
const handleSelect = (cardIndex: number, cardID: string) => {
|
||||
setSelectCard(-1);
|
||||
|
||||
select(cardIndex, cardID);
|
||||
};
|
||||
|
||||
// map our five Tarokka cards to their proper locations in a 3x3 grid
|
||||
// common deck cards: left, top, and right
|
||||
// high deck cards: bottom and center
|
||||
const arrangeCards = (_cell: unknown, index: number) => cards[cardMap[index]];
|
||||
|
||||
return noGame ? (
|
||||
<NotFound />
|
||||
) : cards ? (
|
||||
@@ -58,32 +45,14 @@ export default function GamePage() {
|
||||
)}
|
||||
|
||||
{isDM && <Settings gameData={gameData} changeAction={handleSettings} />}
|
||||
<div className="grid grid-cols-3 grid-rows-3 gap-8 w-fit mx-auto">
|
||||
{Array.from({ length: 9 })
|
||||
.map(arrangeCards)
|
||||
.map((card, index) => (
|
||||
<div key={index} className="aspect-[2/3]}">
|
||||
{card && (
|
||||
<Card
|
||||
dm={isDM}
|
||||
card={card}
|
||||
position={layout[cardMap[index]]}
|
||||
settings={settings}
|
||||
flipAction={() => flipCard(cardMap[index])}
|
||||
redrawAction={() => redraw(cardMap[index])}
|
||||
selectAction={() => setSelectCard(cardMap[index])}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<TarokkaGrid />
|
||||
<Notes gameData={gameData} show={cards.every(({ flipped }) => flipped)} />
|
||||
<CardSelect
|
||||
show={selectDeck}
|
||||
hand={cards}
|
||||
settings={settings}
|
||||
closeAction={() => setSelectCard(-1)}
|
||||
selectAction={(cardID) => handleSelect(selectCard, cardID)}
|
||||
selectAction={select}
|
||||
/>
|
||||
</main>
|
||||
) : null;
|
||||
|
||||
Reference in New Issue
Block a user