diff --git a/frontend/src/GameFilter.tsx b/frontend/src/GameFilter.tsx index 3cc2fd2..774b17f 100644 --- a/frontend/src/GameFilter.tsx +++ b/frontend/src/GameFilter.tsx @@ -12,6 +12,9 @@ export function GameFilter() { const [people, setPeople] = useState([]); const [selectedPeople, setSelectedPeople] = useState>(new Set()); const [filteredGames, setFilteredGames] = useState([]); + const [gameToPositive, setGameToPositive] = useState< + Map> + >(new Map()); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [metaData, _setMetaData] = useState<{ [key: string]: GameProto }>({}); @@ -27,6 +30,7 @@ export function GameFilter() { useEffect(() => { if (selectedPeople.size === 0) { + // eslint-disable-next-line react-hooks/set-state-in-effect setFilteredGames([]); return; } @@ -39,22 +43,31 @@ export function GameFilter() { return; } - // Create a map of game -> set of people who would play it - const gameToPlayers = new Map>(); + // Create a map of game -> set of people who would not play it + const gameToNegative = new Map>(); + const gameToPositiveOpinion = new Map>(); selectedPersons.forEach((person) => { person.opinion.forEach((op) => { - if (!gameToPlayers.has(op.title)) { - gameToPlayers.set(op.title, new Set()); + if (!gameToNegative.has(op.title)) { + gameToNegative.set(op.title, new Set()); + } + if (!gameToPositiveOpinion.has(op.title)) { + gameToPositiveOpinion.set(op.title, new Set()); } if (!op.wouldPlay) { - gameToPlayers.get(op.title)!.add(person.name); + gameToNegative.get(op.title)!.add(person.name); + } + if (op.wouldPlay) { + gameToPositiveOpinion.get(op.title)!.add(person.name); } }); }); + setGameToPositive(gameToPositiveOpinion); + // Filter games where ALL selected people would play - const game_titles = Array.from(gameToPlayers.entries()) + const game_titles = Array.from(gameToNegative.entries()) .filter(([, players]) => players.size === 0) .map(([game]) => game); @@ -169,8 +182,21 @@ export function GameFilter() { marginTop: "0.5rem", }} > - ✓ All {selectedPeople.size} selected would play + ✓ {gameToPositive.get(game)!.size} selected would play + {selectedPeople.size - gameToPositive.get(game)!.size > + 0 && ( +
+ ? {selectedPeople.size - gameToPositive.get(game)!.size}{" "} + {(selectedPeople.size - gameToPositive.get(game)!.size) > 1 ? "are" : "is"} neutral +
+ )}