Skip to content

Commit

Permalink
Merge pull request #31 from alexfauquette/votes
Browse files Browse the repository at this point in the history
Fix abstension count
  • Loading branch information
alexfauquette authored Mar 2, 2024
2 parents 20cd14e + 928b679 commit 2f9c559
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
27 changes: 14 additions & 13 deletions components/folders/VotesTab/DeputeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ type DeputeCardProps = {
fullName: string;
shortName: string;
};
vote?: "pour" | "contre" | "nonVotant";
isDissident?: boolean;
vote?: "pour" | "contre" | "nonVotant" | "abstention";
groupPosition?: "pour" | "contre" | "abstention";
};

export default function DeputeCard(props: DeputeCardProps) {
const { prenom, nom, group, vote, isDissident } = props;
const { prenom, nom, group, vote, groupPosition } = props;

const isDissident = groupPosition !== vote && vote !== "nonVotant";

return (
<Box
Expand Down Expand Up @@ -101,17 +103,16 @@ export default function DeputeCard(props: DeputeCardProps) {
<CompareArrowsSharpIcon />
</Tooltip>
)}
{vote && (
<Tooltip title={vote}>
<CircleDiv
color={
(vote === "pour" && "green") ||
(vote === "contre" && "red") ||
"gray"
}
/>
</Tooltip>
{vote && vote !== "nonVotant" && (
<CircleDiv
color={
(vote === "pour" && "green") ||
(vote === "contre" && "red") ||
"gray"
}
/>
)}
{vote === "nonVotant" && <span>(non votant)</span>}
</Stack>
</Box>
);
Expand Down
10 changes: 5 additions & 5 deletions components/folders/VotesTab/VotesDeputes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export function VotesDeputes({ votes }: { votes: Vote[] }) {
() => votes.filter((vote) => vote.positionVote === "contre"),
[votes]
);
const votesAbstension = React.useMemo(
() => votes.filter((vote) => vote.positionVote === "nonVotant"),
const votesabstention = React.useMemo(
() => votes.filter((vote) => vote.positionVote === "abstention"),
[votes]
);

Expand All @@ -41,8 +41,8 @@ export function VotesDeputes({ votes }: { votes: Vote[] }) {
},
{
color: "gray",
label: "abstension",
votes: votesAbstension,
label: "abstention",
votes: votesabstention,
},
].map(({ color, label, votes: innerVotes }) => (
<React.Fragment key={label}>
Expand Down Expand Up @@ -97,7 +97,7 @@ export function VotesDeputes({ votes }: { votes: Vote[] }) {
color: group_color,
}}
vote={positionVote}
isDissident={group_position !== positionVote}
groupPosition={group_position}
/>
)
)}
Expand Down
10 changes: 6 additions & 4 deletions components/folders/VotesTab/VotesGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type GroupInfo = {
groupId: string;
pour: number;
contre: number;
abstention: number;
nonVotant: number;
fullName: string;
shortName: string;
Expand All @@ -32,6 +33,7 @@ export function VotesGroups({ votes }: { votes: Vote[] }) {
groups[vote.organe_uid] = {
pour: 0,
contre: 0,
abstention: 0,
nonVotant: 0,
fullName: vote.group_libelle,
shortName: vote.group_libelle_short,
Expand All @@ -41,7 +43,7 @@ export function VotesGroups({ votes }: { votes: Vote[] }) {
}

groups[vote.organe_uid][
vote.positionVote as "contre" | "pour" | "nonVotant"
vote.positionVote as "contre" | "pour" | "nonVotant" | "abstention"
] += 1;
groups[vote.organe_uid].votes.push(vote);
});
Expand All @@ -58,7 +60,7 @@ export function VotesGroups({ votes }: { votes: Vote[] }) {
groupId,
pour,
contre,
nonVotant,
abstention,
fullName,
shortName,
color,
Expand Down Expand Up @@ -96,7 +98,7 @@ export function VotesGroups({ votes }: { votes: Vote[] }) {
</Typography>
<CircleDiv color="gray" />
<Typography sx={{ color: "gray", minWidth: 30 }}>
{nonVotant}
{abstention}
</Typography>
</Stack>
</AccordionSummary>
Expand All @@ -118,7 +120,7 @@ export function VotesGroups({ votes }: { votes: Vote[] }) {
prenom={prenom}
nom={nom}
vote={positionVote}
isDissident={group_position !== positionVote}
groupPosition={group_position}
/>
)
)}
Expand Down
9 changes: 6 additions & 3 deletions components/folders/VotesTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Typography,
} from "@mui/material";

type VoteOption = "pour" | "contre" | "nonVotant";
type VoteOption = "pour" | "contre" | "nonVotant" | "abstention";

type VoteProps = {
votes: Vote[];
Expand All @@ -33,6 +33,7 @@ export default function VotesTab({ votes, acts }: VoteProps) {
pour: number;
contre: number;
nonVotant: number;
abstention: number;
}
> = {};
votes.forEach((vote) => {
Expand All @@ -42,6 +43,7 @@ export default function VotesTab({ votes, acts }: VoteProps) {
pour: 0,
contre: 0,
nonVotant: 0,
abstention: 0,
[vote.positionVote]: 1,
};
return;
Expand All @@ -65,6 +67,7 @@ export default function VotesTab({ votes, acts }: VoteProps) {
const act = actsWithVote[actIndex];
const voteSolenel = votesPerAct[act.uid];

console.log(voteSolenel);
return (
<Box sx={{ p: 2 }}>
<Stack direction="row" justifyContent="space-between" sx={{ my: 2 }}>
Expand Down Expand Up @@ -121,7 +124,7 @@ export default function VotesTab({ votes, acts }: VoteProps) {
sx={{ backgroundColor: "red", flexGrow: voteSolenel.contre }}
/>
<Box
sx={{ backgroundColor: "gray", flexGrow: voteSolenel.nonVotant }}
sx={{ backgroundColor: "gray", flexGrow: voteSolenel.abstention }}
/>
</Box>
</Box>
Expand Down Expand Up @@ -168,7 +171,7 @@ export default function VotesTab({ votes, acts }: VoteProps) {
}}
/>
<Typography sx={{ color: "gray" }}>
{voteSolenel.nonVotant} Abstension
{voteSolenel.abstention} abstention
</Typography>
</Box>
<Dialog
Expand Down
13 changes: 10 additions & 3 deletions components/folders/VotesTab/useVoteState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ export function useSearchState<V extends string | number>(

const [isPending, startTransition] = React.useTransition();

const [value, setValue] = React.useState<V>(
(searchParams.get(queryName) as V) ?? defaultValue ?? ""
);
const [value, setValue] = React.useState<V>(() => {
if (typeof defaultValue === "number") {
const rep = Number.parseInt(searchParams.get(queryName) ?? "");
if (!Number.isNaN(rep)) {
return rep as V;
}
return defaultValue ?? (0 as V);
}
return (searchParams.get(queryName) as V) ?? defaultValue ?? ("" as V);
});

function handleUpdate(term: V) {
const params = new URLSearchParams(window.location.search);
Expand Down

0 comments on commit 2f9c559

Please sign in to comment.