-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38c50eb
commit a22b125
Showing
16 changed files
with
455 additions
and
28 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
front-end/src/apps/scorekeeper/hooks/use-match-control.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { MatchState } from '@toa-lib/models'; | ||
import { useRecoilState } from 'recoil'; | ||
import { matchStateAtom } from 'src/stores/recoil'; | ||
|
||
interface MatchControlState { | ||
canPrestart: boolean; | ||
canCancelPrestart: boolean; | ||
canSetDisplays: boolean; | ||
canPrepField: boolean; | ||
canStartMatch: boolean; | ||
canAbortMatch: boolean; | ||
canResetField: boolean; | ||
canCommitScores: boolean; | ||
canPostResults: boolean; | ||
setState: (state: MatchState) => void; | ||
} | ||
|
||
export const useMatchControl = (): MatchControlState => { | ||
const [matchState, setState] = useRecoilState(matchStateAtom); | ||
switch (matchState) { | ||
case MatchState.MATCH_NOT_SELECTED: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.PRESTART_READY: | ||
return { | ||
canPrestart: true, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.PRESTART_COMPLETE: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: true, | ||
canSetDisplays: true, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.AUDIENCE_READY: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: true, | ||
canSetDisplays: true, | ||
canPrepField: true, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.FIELD_READY: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: true, | ||
canSetDisplays: true, | ||
canPrepField: true, | ||
canStartMatch: true, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.MATCH_IN_PROGRESS: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: true, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.MATCH_COMPLETE: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: true, | ||
canCommitScores: true, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.RESULTS_READY: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: true, | ||
canCommitScores: true, | ||
canPostResults: false, | ||
setState | ||
}; | ||
case MatchState.RESULTS_COMMITTED: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: true, | ||
setState | ||
}; | ||
default: | ||
return { | ||
canPrestart: false, | ||
canCancelPrestart: false, | ||
canSetDisplays: false, | ||
canPrepField: false, | ||
canStartMatch: false, | ||
canAbortMatch: false, | ||
canResetField: false, | ||
canCommitScores: false, | ||
canPostResults: false, | ||
setState | ||
}; | ||
} | ||
}; |
31 changes: 31 additions & 0 deletions
31
front-end/src/apps/scorekeeper/match-control/commit-scores-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { useMatchControl } from '../hooks/use-match-control'; | ||
import { MatchState } from '@toa-lib/models'; | ||
|
||
export const CommitScoresButton: FC = () => { | ||
const { canResetField, canCommitScores, setState } = useMatchControl(); | ||
const resetField = () => setState(MatchState.RESULTS_READY); | ||
const commitScores = () => setState(MatchState.RESULTS_COMMITTED); | ||
return canCommitScores ? ( | ||
<Button | ||
fullWidth | ||
color='success' | ||
variant='contained' | ||
onClick={commitScores} | ||
disabled={!canCommitScores} | ||
> | ||
Commit Scores | ||
</Button> | ||
) : ( | ||
<Button | ||
fullWidth | ||
color='success' | ||
variant='contained' | ||
onClick={resetField} | ||
disabled={!canResetField} | ||
> | ||
All Clear | ||
</Button> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
front-end/src/apps/scorekeeper/match-control/displays-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { useMatchControl } from '../hooks/use-match-control'; | ||
import { MatchState } from '@toa-lib/models'; | ||
|
||
export const DisplaysButton: FC = () => { | ||
const { canSetDisplays, setState } = useMatchControl(); | ||
const setDisplays = () => setState(MatchState.AUDIENCE_READY); | ||
return ( | ||
<Button | ||
fullWidth | ||
color='info' | ||
variant='contained' | ||
onClick={setDisplays} | ||
disabled={!canSetDisplays} | ||
> | ||
Set Displays | ||
</Button> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
front-end/src/apps/scorekeeper/match-control/field-prep-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { useMatchControl } from '../hooks/use-match-control'; | ||
import { MatchState } from '@toa-lib/models'; | ||
|
||
export const FieldPrepButton: FC = () => { | ||
const { canPrepField, setState } = useMatchControl(); | ||
const prepareField = () => setState(MatchState.FIELD_READY); | ||
return ( | ||
<Button | ||
fullWidth | ||
color='success' | ||
variant='contained' | ||
onClick={prepareField} | ||
disabled={!canPrepField} | ||
> | ||
Prep Field | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
front-end/src/apps/scorekeeper/match-control/post-results-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { useMatchControl } from '../hooks/use-match-control'; | ||
import { MatchState } from '@toa-lib/models'; | ||
|
||
export const PostResultsButton: FC = () => { | ||
const { canPostResults, setState } = useMatchControl(); | ||
const postResults = () => setState(MatchState.RESULTS_POSTED); | ||
return ( | ||
<Button | ||
fullWidth | ||
color='success' | ||
variant='contained' | ||
onClick={postResults} | ||
disabled={!canPostResults} | ||
> | ||
Post Results | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
front-end/src/apps/scorekeeper/match-control/start-match-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Button } from '@mui/material'; | ||
import { FC } from 'react'; | ||
import { useMatchControl } from '../hooks/use-match-control'; | ||
import { MatchState } from '@toa-lib/models'; | ||
|
||
export const StartMatchButton: FC = () => { | ||
const { canStartMatch, canAbortMatch, setState } = useMatchControl(); | ||
const startMatch = () => setState(MatchState.MATCH_IN_PROGRESS); | ||
const abortMatch = () => setState(MatchState.PRESTART_READY); | ||
return canStartMatch ? ( | ||
<Button | ||
fullWidth | ||
color='error' | ||
variant='contained' | ||
onClick={startMatch} | ||
disabled={!canStartMatch} | ||
> | ||
Start Match | ||
</Button> | ||
) : ( | ||
<Button | ||
fullWidth | ||
color='error' | ||
variant='contained' | ||
onClick={abortMatch} | ||
disabled={!canAbortMatch} | ||
> | ||
Abort Match | ||
</Button> | ||
); | ||
}; |
Oops, something went wrong.