From 5f6d8cc2eca9403d364ff71f01a0013aac5f973c Mon Sep 17 00:00:00 2001 From: Elijah Steres Date: Thu, 14 Jan 2021 17:58:24 -0500 Subject: [PATCH 1/2] fix numerical inputs in league options also clean up some eslint warnings --- simmadome/src/CreateLeague.tsx | 16 ++++++++++------ simmadome/src/GamesPage.tsx | 1 + simmadome/src/GamesUtil.tsx | 1 + simmadome/src/index.tsx | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/simmadome/src/CreateLeague.tsx b/simmadome/src/CreateLeague.tsx index 3a4dbe4..3c23a22 100644 --- a/simmadome/src/CreateLeague.tsx +++ b/simmadome/src/CreateLeague.tsx @@ -195,7 +195,7 @@ function shallowClone(obj: T): T { } type DistributiveOmit = T extends any ? Omit : never; -type DistributivePick = T extends any ? Pick : never; +//type DistributivePick = T extends any ? Pick : never; // CREATE LEAGUE @@ -323,7 +323,7 @@ function validRequest(name:string, structure: LeagueStructureState, options:Leag } function validNumber(value: string, min = 1) { - return Number(value) !== NaN && Number(value) >= min + return !isNaN(Number(value)) && Number(value) >= min } // LEAGUE STRUCUTRE @@ -464,7 +464,7 @@ function LeagueOptions(props: {state: LeagueOptionsState, dispatch: React.Dispat props.dispatch({type: 'set_games_series', value: value})} showError={props.showError}/> props.dispatch({type: 'set_top_postseason', value: value})} showError={props.showError}/> - + props.dispatch({type: 'set_wildcards', value: value})} showError={props.showError}/>
@@ -479,12 +479,16 @@ function LeagueOptions(props: {state: LeagueOptionsState, dispatch: React.Dispat ); } -function NumberInput(props: {title: string, value: string, setValue: (newVal: string) => void, showError: boolean}) { +function NumberInput(props: {title: string, value: string, setValue: (newVal: string) => void, showError: boolean, minValue?:number}) { + let minValue = 1; + if (props.minValue !== undefined) { + minValue = props.minValue + } return (
{props.title}
- props.setValue(e.target.value)}/> -
{(Number(props.value) === NaN || Number(props.value) < 0) && props.showError ? "Must be a number greater than 0" : ""}
+ props.setValue(e.target.value)}/> +
{(!isNaN(Number(props.value)) || Number(props.value) < minValue) && props.showError ? "Must be a number greater than "+minValue : ""}
); } diff --git a/simmadome/src/GamesPage.tsx b/simmadome/src/GamesPage.tsx index 3a2ad97..4fdaacb 100644 --- a/simmadome/src/GamesPage.tsx +++ b/simmadome/src/GamesPage.tsx @@ -8,6 +8,7 @@ function GamesPage() { let [search, setSearch] = useState(window.location.search); useEffect(() => { setSearch(window.location.search); + //eslint-disable-next-line react-hooks/exhaustive-deps }, [window.location.search]) let searchparams = new URLSearchParams(search); diff --git a/simmadome/src/GamesUtil.tsx b/simmadome/src/GamesUtil.tsx index 8002c02..d590399 100644 --- a/simmadome/src/GamesUtil.tsx +++ b/simmadome/src/GamesUtil.tsx @@ -32,6 +32,7 @@ const useListener = (onUpdate: (update: [string, GameState][]) => void, url: str socket.on('connect', () => socket.emit('recieved', {})); socket.on('states_update', onUpdate); return () => {socket.disconnect()}; + //eslint-disable-next-line react-hooks/exhaustive-deps }, [url]) } diff --git a/simmadome/src/index.tsx b/simmadome/src/index.tsx index e6a49c9..b0ec638 100644 --- a/simmadome/src/index.tsx +++ b/simmadome/src/index.tsx @@ -32,14 +32,14 @@ function Header() {