Skip to content

Commit e629d92

Browse files
authored
Merge pull request #1477 from kleros/feat(web)/improve-voting-history-accordion-or-cards
feat(web): improve votinghistory styling, show cards instead of accordions
2 parents ad24ce1 + 81f6f9b commit e629d92

File tree

4 files changed

+74
-34
lines changed

4 files changed

+74
-34
lines changed

web/src/pages/Cases/CaseDetails/Voting/PendingVotesBox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import BalanceIcon from "svgs/icons/law-balance.svg";
55

66
const StyledBox = styled(Box)`
77
width: 100%;
8+
background-color: ${({ theme }) => theme.lightBlue};
89
height: auto;
910
border-radius: 3px;
10-
padding: 8px 16px;
11+
padding: 16px;
1112
display: flex;
1213
gap: 8px;
1314
align-items: center;

web/src/pages/Cases/CaseDetails/Voting/VotesDetails/AccordionTitle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const VoteStatus: React.FC<{
4242
isActiveRound: boolean;
4343
}> = ({ choice, period, answers, isActiveRound }) => {
4444
if (isUndefined(choice) && (isActiveRound ? ["appeal", "execution"].includes(period) : true))
45-
return <StyledLabel>Didn't cast a vote</StyledLabel>;
45+
return <StyledLabel>Did not vote</StyledLabel>;
4646
return (
4747
<StyledLabel>
4848
{isUndefined(choice) ? "Pending Vote" : <StyledSmall>{getVoteChoice(parseInt(choice), answers)}</StyledSmall>}

web/src/pages/Cases/CaseDetails/Voting/VotesDetails/index.tsx

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { CustomAccordion } from "@kleros/ui-components-library";
2-
import React from "react";
1+
import { Card, CustomAccordion } from "@kleros/ui-components-library";
2+
import React, { useMemo } from "react";
33
import styled from "styled-components";
44
import { Answer } from "context/NewDisputeContext";
55
import { DrawnJuror } from "utils/getDrawnJurorsWithCount";
@@ -9,6 +9,12 @@ import { responsiveSize } from "styles/responsiveSize";
99
import { getVoteChoice } from "utils/getVoteChoice";
1010
import { isUndefined } from "utils/index";
1111

12+
const Container = styled.div`
13+
display: flex;
14+
flex-direction: column;
15+
margin-top: 8px;
16+
`;
17+
1218
const StyledAccordion = styled(CustomAccordion)`
1319
width: 100%;
1420
> * > button {
@@ -22,10 +28,17 @@ const StyledAccordion = styled(CustomAccordion)`
2228
}
2329
//adds padding to body container
2430
> * > div > div {
25-
padding: ${responsiveSize(8, 24)} ${responsiveSize(8, 16)};
31+
padding: ${responsiveSize(16, 24)} ${responsiveSize(8, 16)};
2632
}
2733
`;
2834

35+
const StyledCard = styled(Card)`
36+
width: 100%;
37+
height: auto;
38+
padding: 11.5px ${responsiveSize(8, 18)};
39+
margin: 8px 0;
40+
`;
41+
2942
const AccordionContentContainer = styled.div`
3043
display: flex;
3144
flex-direction: column;
@@ -72,42 +85,67 @@ const AccordionContent: React.FC<{
7285
</AccordionContentContainer>
7386
);
7487

75-
interface VotesAccordion {
88+
interface IVotesAccordion {
7689
drawnJurors: DrawnJuror[];
7790
period: string;
7891
answers: Answer[];
7992
isActiveRound: boolean;
8093
}
8194

82-
const VotesAccordion: React.FC<VotesAccordion> = ({ drawnJurors, period, answers, isActiveRound }) => {
83-
return drawnJurors.length ? (
84-
<StyledAccordion
85-
items={
86-
drawnJurors?.map((drawnJuror) => ({
87-
title: (
88-
<AccordionTitle
89-
juror={drawnJuror.juror.id}
90-
voteCount={drawnJuror.voteCount}
91-
choice={drawnJuror.vote?.justification?.choice}
92-
period={period}
93-
answers={answers}
94-
isActiveRound={isActiveRound}
95-
/>
96-
),
97-
body: drawnJuror.vote?.justification?.choice ? (
98-
<AccordionContent
99-
justification={drawnJuror?.vote?.justification.reference ?? ""}
100-
choice={drawnJuror.vote?.justification?.choice}
101-
answers={answers}
102-
/>
103-
) : null,
104-
})) ?? []
105-
}
106-
/>
107-
) : (
95+
const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answers, isActiveRound }) => {
96+
const accordionItems = useMemo(() => {
97+
return drawnJurors
98+
.map((drawnJuror) =>
99+
!isUndefined(drawnJuror.vote?.justification?.choice)
100+
? {
101+
title: (
102+
<AccordionTitle
103+
juror={drawnJuror.juror.id}
104+
voteCount={drawnJuror.voteCount}
105+
choice={drawnJuror.vote?.justification?.choice}
106+
period={period}
107+
answers={answers}
108+
isActiveRound={isActiveRound}
109+
/>
110+
),
111+
body: (
112+
<AccordionContent
113+
justification={drawnJuror?.vote?.justification.reference ?? ""}
114+
choice={drawnJuror.vote?.justification?.choice}
115+
answers={answers}
116+
/>
117+
),
118+
}
119+
: null
120+
)
121+
.filter((item) => item !== null);
122+
}, [drawnJurors, period, answers, isActiveRound]);
123+
124+
return (
108125
<>
109-
<br />
110-
<InfoCard msg="Jurors have not been drawn yet." />
126+
{drawnJurors.length === 0 ? (
127+
<>
128+
<br />
129+
<InfoCard msg="Jurors have not been drawn yet." />
130+
</>
131+
) : null}
132+
<Container>
133+
{accordionItems.length > 0 ? <StyledAccordion items={accordionItems} /> : null}
134+
{drawnJurors.map(
135+
(drawnJuror) =>
136+
isUndefined(drawnJuror.vote?.justification?.choice) && (
137+
<StyledCard key={drawnJuror.juror.id}>
138+
<AccordionTitle
139+
juror={drawnJuror.juror.id}
140+
voteCount={drawnJuror.voteCount}
141+
period={period}
142+
answers={answers}
143+
isActiveRound={isActiveRound}
144+
/>
145+
</StyledCard>
146+
)
147+
)}
148+
</Container>
111149
</>
112150
);
113151
};

web/src/pages/Cases/CaseDetails/Voting/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useVotingContext } from "hooks/useVotingContext";
2121

2222
const Container = styled.div`
2323
padding: ${responsiveSize(16, 32)};
24+
padding-bottom: ${responsiveSize(8, 16)};
2425
`;
2526

2627
const useFinalDate = (lastPeriodChange: string, currentPeriodIndex?: number, timesPerPeriod?: string[]) =>

0 commit comments

Comments
 (0)