show neutral amount
This commit is contained in:
parent
f2e4f23c42
commit
4ee3b8248a
@ -12,6 +12,9 @@ export function GameFilter() {
|
|||||||
const [people, setPeople] = useState<Person[]>([]);
|
const [people, setPeople] = useState<Person[]>([]);
|
||||||
const [selectedPeople, setSelectedPeople] = useState<Set<string>>(new Set());
|
const [selectedPeople, setSelectedPeople] = useState<Set<string>>(new Set());
|
||||||
const [filteredGames, setFilteredGames] = useState<string[]>([]);
|
const [filteredGames, setFilteredGames] = useState<string[]>([]);
|
||||||
|
const [gameToPositive, setGameToPositive] = useState<
|
||||||
|
Map<string, Set<string>>
|
||||||
|
>(new Map());
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const [metaData, _setMetaData] = useState<{ [key: string]: GameProto }>({});
|
const [metaData, _setMetaData] = useState<{ [key: string]: GameProto }>({});
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ export function GameFilter() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedPeople.size === 0) {
|
if (selectedPeople.size === 0) {
|
||||||
|
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||||
setFilteredGames([]);
|
setFilteredGames([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -39,22 +43,31 @@ export function GameFilter() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a map of game -> set of people who would play it
|
// Create a map of game -> set of people who would not play it
|
||||||
const gameToPlayers = new Map<string, Set<string>>();
|
const gameToNegative = new Map<string, Set<string>>();
|
||||||
|
const gameToPositiveOpinion = new Map<string, Set<string>>();
|
||||||
|
|
||||||
selectedPersons.forEach((person) => {
|
selectedPersons.forEach((person) => {
|
||||||
person.opinion.forEach((op) => {
|
person.opinion.forEach((op) => {
|
||||||
if (!gameToPlayers.has(op.title)) {
|
if (!gameToNegative.has(op.title)) {
|
||||||
gameToPlayers.set(op.title, new Set());
|
gameToNegative.set(op.title, new Set());
|
||||||
|
}
|
||||||
|
if (!gameToPositiveOpinion.has(op.title)) {
|
||||||
|
gameToPositiveOpinion.set(op.title, new Set());
|
||||||
}
|
}
|
||||||
if (!op.wouldPlay) {
|
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
|
// 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)
|
.filter(([, players]) => players.size === 0)
|
||||||
.map(([game]) => game);
|
.map(([game]) => game);
|
||||||
|
|
||||||
@ -169,8 +182,21 @@ export function GameFilter() {
|
|||||||
marginTop: "0.5rem",
|
marginTop: "0.5rem",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
✓ All {selectedPeople.size} selected would play
|
✓ {gameToPositive.get(game)!.size} selected would play
|
||||||
</div>
|
</div>
|
||||||
|
{selectedPeople.size - gameToPositive.get(game)!.size >
|
||||||
|
0 && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: "0.9em",
|
||||||
|
color: "#d4d400",
|
||||||
|
marginTop: "0.3rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
? {selectedPeople.size - gameToPositive.get(game)!.size}{" "}
|
||||||
|
{(selectedPeople.size - gameToPositive.get(game)!.size) > 1 ? "are" : "is"} neutral
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<GameImage game={game} />
|
<GameImage game={game} />
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user