Skip to content

Commit

Permalink
fix: prevent negative draw count
Browse files Browse the repository at this point in the history
  • Loading branch information
OldStarchy committed Jun 21, 2024
1 parent 19e22c8 commit e9cce72
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<Dispatch<SetStateAction<number>>>(
(count) => {
setDrawCountRaw((c) =>
Math.max(1, typeof count === 'number' ? count : count(c))
);
},
[setDrawCountRaw]
);

const infectionNonce = useMutable(infectionDeck);
useMutable(discardDeck);

Expand Down

0 comments on commit e9cce72

Please sign in to comment.