refactoring
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user