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" ;
33import styled from "styled-components" ;
44import { Answer } from "context/NewDisputeContext" ;
55import { DrawnJuror } from "utils/getDrawnJurorsWithCount" ;
@@ -9,6 +9,12 @@ import { responsiveSize } from "styles/responsiveSize";
99import { getVoteChoice } from "utils/getVoteChoice" ;
1010import { isUndefined } from "utils/index" ;
1111
12+ const Container = styled . div `
13+ display: flex;
14+ flex-direction: column;
15+ margin-top: 8px;
16+ ` ;
17+
1218const 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+
2942const 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} ;
0 commit comments