From e9cce720e1507e84c740704a47e52ae9f82ac3c7 Mon Sep 17 00:00:00 2001 From: Nicholas Sorokin Date: Sat, 22 Jun 2024 04:06:58 +0930 Subject: [PATCH] fix: prevent negative draw count --- src/App.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 3a3c5fc..a4acf31 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,11 @@ -import { useCallback, useEffect, useMemo, useState } from 'react'; +import { + Dispatch, + SetStateAction, + useCallback, + useEffect, + useMemo, + useState, +} from 'react'; import './App.css'; import { CardBase } from './components/CardBase'; import { cities } from './data/cities'; @@ -52,10 +59,19 @@ function createStripeyBackground(colors: string[]): string { } function App() { - const [drawCount, setDrawCount] = useState(1); + const [drawCount, setDrawCountRaw] = useState(1); const [topDrawFormVisible, setTopDrawFormVisible] = useState(false); const [bottomDrawFormVisible, setBottomDrawFormVisible] = useState(false); + const setDrawCount = useCallback>>( + (count) => { + setDrawCountRaw((c) => + Math.max(1, typeof count === 'number' ? count : count(c)) + ); + }, + [setDrawCountRaw] + ); + const infectionNonce = useMutable(infectionDeck); useMutable(discardDeck);