refactoring

This commit is contained in:
Gavin McDonald
2025-06-26 13:59:27 -04:00
parent 1c28a603b7
commit 12ae8dd6d8
4 changed files with 58 additions and 56 deletions

View File

@@ -26,14 +26,16 @@ export interface AppContext {
flipCard: (cardIndex: number) => void;
handleSettings: (gameData: GameUpdate) => void;
redraw: (cardIndex: number) => void;
select: (cardIndex: number, cardID: string) => void;
select: (cardID: string) => void;
setGameID: (gameID: string) => void;
setSelectCardIndex: (cardIndex: number) => void;
setTilts: (tilts: Tilt[]) => void;
}
export function AppProvider({ children }: { children: ReactNode }) {
const [gameID, setGameID] = useState('');
const [noGame, setNoGame] = useState(false);
const [selectCardIndex, setSelectCardIndex] = useState(-1);
const [gameData, setGameData] = useState<GameUpdate>(gameStart);
const { flipCard, redraw, select, handleSettings } = useSocket({
@@ -44,6 +46,12 @@ export function AppProvider({ children }: { children: ReactNode }) {
const [tilts, setTilts] = useState<Tilt[]>([]);
const handleSelect = (cardID: string) => {
setSelectCardIndex(-1);
select(selectCardIndex, cardID);
};
const appInterface = {
gameData,
noGame,
@@ -51,8 +59,9 @@ export function AppProvider({ children }: { children: ReactNode }) {
flipCard,
handleSettings,
redraw,
select,
select: handleSelect,
setGameID,
setSelectCardIndex,
setTilts,
};