-
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.
Merge remote-tracking branch 'origin/main' into fgc-2024-fcs
- Loading branch information
Showing
27 changed files
with
1,223 additions
and
368 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
front-end/src/apps/scorekeeper/hooks/use-next-unplayed-match.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,44 @@ | ||
import { useRecoilCallback, useRecoilValue } from 'recoil'; | ||
import { | ||
currentEventKeyAtom, | ||
currentMatchIdAtom, | ||
currentTournamentKeyAtom, | ||
matchOccurringAtom | ||
} from 'src/stores/recoil'; | ||
import { useMatchesForTournament } from 'src/api/use-match-data'; | ||
import { useActiveFieldNumbers } from 'src/components/sync-effects/sync-fields-to-recoil'; | ||
|
||
export const useNextUnplayedMatch = () => { | ||
const eventKey = useRecoilValue(currentEventKeyAtom); | ||
const tournamentKey = useRecoilValue(currentTournamentKeyAtom); | ||
const { data: matches } = useMatchesForTournament(eventKey, tournamentKey); | ||
const [activeFields] = useActiveFieldNumbers(); | ||
|
||
return useRecoilCallback( | ||
({ snapshot }) => | ||
async () => { | ||
const match = await snapshot.getPromise(matchOccurringAtom); | ||
|
||
if (!match) { | ||
return null; | ||
} | ||
|
||
// Try to find the next match and select it | ||
if (matches) { | ||
const ourMatches = matches | ||
.filter((m) => activeFields.includes(m.fieldNumber)) | ||
.sort((a, b) => a.id - b.id); | ||
|
||
// Find the next match that hasn't had results posted | ||
const index = ourMatches.findIndex( | ||
(m) => m.id >= match.id && m.result < 0 | ||
); | ||
if (ourMatches[index]) { | ||
return ourMatches[index]; | ||
} | ||
} | ||
return null; | ||
}, | ||
[matches, eventKey, tournamentKey, activeFields] | ||
); | ||
}; |
Oops, something went wrong.