@@ -41,7 +41,7 @@ type BallotProps = {
4141 type : BallotType
4242 structure : BallotStructure
4343 votes : Vote [ ]
44- toggleVote : (
44+ toggleVote ? : (
4545 candidate : ElectiveField ,
4646 { row, column } : VotesCoordinates
4747 ) => void
@@ -52,8 +52,8 @@ export default function BaseBallot(props: BallotProps) {
5252 props . type === BallotType . state
5353 ? "bg-ballots-governmental"
5454 : props . type === BallotType . municipality
55- ? "bg-ballots-municipal"
56- : "bg-ballots-legislative"
55+ ? "bg-ballots-municipal"
56+ : "bg-ballots-legislative"
5757 const { highlightedColumn } = useColumnHighlight ( )
5858 const isLegislativeBallot = props . type === BallotType . legislative
5959 const ballotWidth =
@@ -72,129 +72,133 @@ export default function BaseBallot(props: BallotProps) {
7272 rowIndex !== 0 ? ballotBg : ""
7373 } `}
7474 >
75- { row . map (
76- ( col : Party | Rule | Candidate | Header , colIndex : number ) => {
77- const vote = props . votes . find ( vote => {
78- return (
79- vote . position . row === rowIndex &&
80- vote . position . column === colIndex
81- )
82- } )
83- const hasVote = ! ! vote
84- const isExplicitVote = hasVote
85- ? ( vote as Vote ) . wasSelectedExplictly ( )
86- : false
87- const isImplicitVote = hasVote
88- ? ( vote as Vote ) . wasSelectedImplicitly ( )
89- : false
90- const isHighlighted = colIndex === highlightedColumn
91- const voteType = isExplicitVote
92- ? "explicit-vote"
93- : isImplicitVote
75+ { row . map ( ( col , colIndex ) => {
76+ const vote = props . votes . find ( ( vote ) => {
77+ return (
78+ vote . position . row === rowIndex &&
79+ vote . position . column === colIndex
80+ )
81+ } )
82+ const hasVote = ! ! vote
83+ const isExplicitVote = hasVote
84+ ? ( vote as Vote ) . wasSelectedExplictly ( )
85+ : false
86+ const isImplicitVote = hasVote
87+ ? ( vote as Vote ) . wasSelectedImplicitly ( )
88+ : false
89+ const isHighlighted = colIndex === highlightedColumn
90+ const voteType = isExplicitVote
91+ ? "explicit-vote"
92+ : isImplicitVote
9493 ? "implicit-vote"
9594 : "no-vote"
96- const voteOpacity = isExplicitVote
97- ? "opacity-100"
98- : isImplicitVote
95+ const voteOpacity = isExplicitVote
96+ ? "opacity-100"
97+ : isImplicitVote
9998 ? "opacity-25"
10099 : ""
101100
102- if ( col instanceof Party ) {
103- return (
104- < Ballot . PoliticalParty
105- key = { col . id }
106- voteType = { voteType }
107- logo = { col . insignia }
108- ocrResult = { col . name }
109- hasVote = { hasVote }
110- voteOpacity = { voteOpacity }
111- position = { colIndex }
112- isHighlighted = { isHighlighted }
113- toggleVote = { ( ) =>
114- props . toggleVote ( col , {
115- row : rowIndex ,
116- column : colIndex ,
117- } )
118- }
119- />
120- )
121- }
101+ if ( col instanceof Party ) {
102+ return (
103+ < Ballot . PoliticalParty
104+ key = { col . id }
105+ voteType = { voteType }
106+ logo = { col . insignia }
107+ ocrResult = { col . name }
108+ hasVote = { hasVote }
109+ voteOpacity = { voteOpacity }
110+ position = { colIndex }
111+ isHighlighted = { isHighlighted }
112+ toggleVote = { ( ) => {
113+ if ( props . toggleVote == null ) return
122114
123- if ( col instanceof WriteInRules ) {
124- return (
125- < Ballot . WriteInRules
126- key = { col . id }
127- esTitle = { col . esTitle }
128- esRules = { col . esRules }
129- enTitle = { col . enTitle }
130- enRules = { col . enRules }
131- />
132- )
133- }
115+ props . toggleVote ( col , {
116+ row : rowIndex ,
117+ column : colIndex ,
118+ } )
119+ } }
120+ />
121+ )
122+ }
134123
135- if ( col instanceof Rule ) {
136- return < Ballot . Rule key = { col . id } ocrResult = { col . rule } />
137- }
124+ if ( col instanceof WriteInRules ) {
125+ return (
126+ < Ballot . WriteInRules
127+ key = { col . id }
128+ esTitle = { col . esTitle }
129+ esRules = { col . esRules }
130+ enTitle = { col . enTitle }
131+ enRules = { col . enRules }
132+ />
133+ )
134+ }
138135
139- if ( col instanceof Candidate ) {
140- return (
141- < Ballot . Candidate
142- key = { col . id }
143- img = { col . img }
144- name = { col . name }
145- hasVote = { hasVote }
146- voteType = { voteType }
147- voteOpacity = { voteOpacity }
148- accumulationNumber = { col . accumulationNumber }
149- isHighlighted = { isHighlighted }
150- isPartyHighlighted = {
151- isLegislativeBallot
152- ? col . receivesImpicitVote && isHighlighted
153- : isHighlighted
154- }
155- toggleVote = { ( ) =>
156- props . toggleVote ( col , {
157- row : rowIndex ,
158- column : colIndex ,
159- } )
160- }
161- />
162- )
163- }
136+ if ( col instanceof Rule ) {
137+ return < Ballot . Rule key = { col . id } ocrResult = { col . rule } />
138+ }
164139
165- if ( col instanceof WriteInCandidate ) {
166- return (
167- < Ballot . WriteIn
168- key = { col . id }
169- accumulationNumber = { col . accumulationNumber }
170- hasVote = { hasVote }
171- voteOpacity = { voteOpacity }
172- voteType = { voteType }
173- toggleVote = { ( ) =>
174- props . toggleVote ( col , {
175- row : rowIndex ,
176- column : colIndex ,
177- } )
178- }
179- initialTextValue = { col . name || vote ?. candidate ?. name }
180- updateName = { ( name : string ) => col . setName ( name ) }
181- />
182- )
183- }
140+ if ( col instanceof Candidate ) {
141+ return (
142+ < Ballot . Candidate
143+ key = { col . id }
144+ img = { col . img }
145+ name = { col . name }
146+ hasVote = { hasVote }
147+ voteType = { voteType }
148+ voteOpacity = { voteOpacity }
149+ accumulationNumber = { col . accumulationNumber }
150+ isHighlighted = { isHighlighted }
151+ isPartyHighlighted = {
152+ isLegislativeBallot
153+ ? col . receivesImpicitVote && isHighlighted
154+ : isHighlighted
155+ }
156+ toggleVote = { ( ) => {
157+ if ( props . toggleVote == null ) return
184158
185- if ( col instanceof EmptyCandidacy ) {
186- return < Ballot . EmptyCandidacy key = { col . id } />
187- }
159+ props . toggleVote ( col , {
160+ row : rowIndex ,
161+ column : colIndex ,
162+ } )
163+ } }
164+ />
165+ )
166+ }
188167
168+ if ( col instanceof WriteInCandidate ) {
189169 return (
190- < Ballot . SectionHeader
170+ < Ballot . WriteIn
191171 key = { col . id }
192- ocrResult = { col . info }
193- slug = { col . slug }
172+ accumulationNumber = { col . accumulationNumber }
173+ hasVote = { hasVote }
174+ voteOpacity = { voteOpacity }
175+ voteType = { voteType }
176+ toggleVote = { ( ) => {
177+ if ( props . toggleVote == null ) return
178+
179+ props . toggleVote ( col , {
180+ row : rowIndex ,
181+ column : colIndex ,
182+ } )
183+ } }
184+ initialTextValue = { col . name || vote ?. candidate ?. name }
185+ updateName = { ( name : string ) => col . setName ( name ) }
194186 />
195187 )
196188 }
197- ) }
189+
190+ if ( col instanceof EmptyCandidacy ) {
191+ return < Ballot . EmptyCandidacy key = { col . id } />
192+ }
193+
194+ return (
195+ < Ballot . SectionHeader
196+ key = { col . id }
197+ ocrResult = { col . info }
198+ slug = { col . slug }
199+ />
200+ )
201+ } ) }
198202 </ div >
199203 )
200204 }
0 commit comments