Skip to content

Commit 225e975

Browse files
authored
Merge pull request #152 from dedis/front-num-voters
Display the number of ballot cast so far on election page
2 parents 0c9bfc4 + 05d590f commit 225e975

File tree

13 files changed

+566
-136
lines changed

13 files changed

+566
-136
lines changed

web/frontend/src/components/utils/FillElectionInfo.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const useFillElectionInfo = (electionData: ElectionInfo) => {
1111
const [chunksPerBallot, setChunksPerBallot] = useState<number>(0);
1212
const [ballotSize, setBallotSize] = useState<number>(0);
1313
const [configObj, setConfigObj] = useState(null);
14+
const [voters, setVoters] = useState<string[]>(null);
1415
const [isResultSet, setIsResultSet] = useState<boolean>(false);
1516

1617
useEffect(() => {
@@ -23,6 +24,8 @@ const useFillElectionInfo = (electionData: ElectionInfo) => {
2324
setChunksPerBallot(electionData.ChunksPerBallot);
2425
setBallotSize(electionData.BallotSize);
2526
setConfigObj(electionData.Configuration);
27+
setVoters(electionData.Voters);
28+
2629
if (electionData.Result.length > 0) {
2730
setIsResultSet(true);
2831
}
@@ -42,6 +45,7 @@ const useFillElectionInfo = (electionData: ElectionInfo) => {
4245
configObj,
4346
isResultSet,
4447
setIsResultSet,
48+
voters,
4549
};
4650
};
4751

web/frontend/src/components/utils/useElection.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const useElection = (electionID: ID) => {
2929
configObj,
3030
isResultSet,
3131
setIsResultSet,
32+
voters,
3233
} = useFillElectionInfo(data);
3334

3435
return {
@@ -45,6 +46,7 @@ const useElection = (electionID: ID) => {
4546
configObj,
4647
isResultSet,
4748
setIsResultSet,
49+
voters,
4850
error,
4951
};
5052
};

web/frontend/src/language/en.json

+13-6
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
"enterSubjectTitle": "Enter the Subject Title",
8787
"errorCandidates": "You must add at least one candidate!",
8888
"errorNewCandidate": "Are you sure you don't want to add ",
89-
"errorRetrievingElections": "An error seems to have occurred while retrieving all the elections from our server. Contact the administrator of this website.",
90-
"errorRetrievingElection": "An error seems to have occurred while retrieving the election from our server. Contact the administrator of this website.",
91-
"errorRetrievingProxy": "An error seems to have occurred while retrieving the addresses of the proxies from our server. Contact the administrator of this website.",
92-
"errorRetrievingNodes": "An error seems to have occurred while retrieving the status of the nodes from our server. Contact the administrator of this website.",
89+
"errorRetrievingElections": "An error seems to have occurred while retrieving all the elections from our server. Contact the administrator of this website. Error: ",
90+
"errorRetrievingElection": "An error seems to have occurred while retrieving the election from our server. Contact the administrator of this website. Error: ",
91+
"errorRetrievingProxy": "An error seems to have occurred while retrieving the addresses of the proxies from our server. Contact the administrator of this website. ",
92+
"errorRetrievingNodes": "An error seems to have occurred while retrieving the status of the nodes from our server. Contact the administrator of this website. ",
9393
"errorRetrievingKey": "An error seems to have occurred while retrieving the public key from our server. Contact the administrator of this website.",
9494
"errorServerDown": "One of our servers seems to be down. Contact the administrator of this website.",
9595
"electionSuccess": "Your election was successfully submitted!",
@@ -160,7 +160,7 @@
160160
"errorRemoveUser": "Error while removing the user",
161161
"errorFetchingUsers": "Error while fetching the users",
162162
"voteFailure": "Your ballot hasn't been taken into account. It might be that the election has been closed or cancelled. Try refreshing the page.",
163-
"ballotFailure": "An error occurred while sending your ballot. Please contact the administrator of this website",
163+
"ballotFailure": "An error occurred while sending your ballot. Please contact the administrator of this website. ",
164164
"incompleteBallot": "Some answers are not complete.",
165165
"selectMin": "Select {{minSelect}} {{singularPlural}}. ",
166166
"selectMax": "Select at most {{maxSelect}} {{singularPlural}}. ",
@@ -236,6 +236,13 @@
236236
"invalidProxyError": "Error: the address you entered is not a valid URL.",
237237
"learnMore": "Learn more about D-Voting platform",
238238
"aboutPlatform": "About the Platform",
239-
"whatMakesUsDifferent": "What makes us different"
239+
"whatMakesUsDifferent": "What makes us different",
240+
"numVotes": "Number of ballot cast: {{num}}",
241+
"userID": "User ID of voters",
242+
"nodeUnreachable": "Timeout: the node ({{node}}) could not be reached. ",
243+
"proxyUnreachable": "Timeout: the address of the proxy for the node ({{node}}) could not be resolved. ",
244+
"error": "Error: ",
245+
"actionLoading": "Action loading...",
246+
"statusLoading": "Status loading..."
240247
}
241248
}

web/frontend/src/layout/Footer.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ const Footer = () => (
55
<footer>
66
<div className="hidden sm:flex flex-row items-center max-w-7xl mx-auto py-2 px-4 overflow-hidden sm:px-6 lg:px-8">
77
<span className="text-gray-400"> &copy; 2022 DEDIS LAB - </span>
8-
<a className="text-gray-600" href="https://github.com/dedis/dela">
9-
https://github.com/dedis/dela
8+
<a className="text-gray-600" href="https://github.com/dedis/d-voting">
9+
https://github.com/dedis/d-voting
1010
</a>
1111
<div className="px-10">
1212
<ProxyInput />
1313
</div>
1414
</div>
1515
<div className="flex sm:hidden flex-col items-center max-w-7xl mx-auto py-2 px-4 overflow-hidden sm:px-6 lg:px-8">
1616
<span className="text-gray-400"> &copy; 2022 DEDIS LAB - </span>
17-
<a className="text-gray-600" href="https://github.com/dedis/dela">
18-
https://github.com/dedis/dela
17+
<a className="text-gray-600" href="https://github.com/dedis/d-voting">
18+
https://github.com/dedis/d-voting
1919
</a>
2020
<div className="pt-2">
2121
<ProxyInput />

web/frontend/src/mocks/handlers.ts

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export const handlers = [
142142
Configuration: configuration,
143143
BallotSize: 291,
144144
ChunksPerBallot: 11,
145+
Voters: [],
145146
});
146147

147148
return newElectionID;
@@ -157,8 +158,18 @@ export const handlers = [
157158

158159
rest.post(endpoints.newElectionVote(':ElectionID'), async (req, res, ctx) => {
159160
const { Ballot }: NewElectionVoteBody = req.body as NewElectionVoteBody;
161+
const { ElectionID } = req.params;
162+
160163
await new Promise((r) => setTimeout(r, RESPONSE_TIME));
161164

165+
const Voters = mockElections.get(ElectionID as string).Voters;
166+
Voters.push('userID' + (Voters.length + 1));
167+
168+
mockElections.set(ElectionID as string, {
169+
...mockElections.get(ElectionID as string),
170+
Voters,
171+
});
172+
162173
return res(
163174
ctx.status(200),
164175
ctx.json({

web/frontend/src/mocks/setupMockElections.ts

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const setupMockElection = () => {
5454
Configuration: unmarshalConfig(mockElection1),
5555
BallotSize: 174,
5656
ChunksPerBallot: 6,
57+
Voters: [],
5758
});
5859

5960
mockResults.set(electionID1, [mockElectionResult11, mockElectionResult12]);
@@ -69,6 +70,7 @@ const setupMockElection = () => {
6970
Configuration: unmarshalConfig(mockElection2),
7071
BallotSize: 174,
7172
ChunksPerBallot: 6,
73+
Voters: ['aefae', 'ozeivn', 'ovaeop'],
7274
});
7375

7476
mockResults.set(electionID2, [mockElectionResult21, mockElectionResult22, mockElectionResult23]);
@@ -83,6 +85,7 @@ const setupMockElection = () => {
8385
Configuration: unmarshalConfig(mockElection3),
8486
BallotSize: 291,
8587
ChunksPerBallot: 11,
88+
Voters: [],
8689
});
8790

8891
mockResults.set(electionID3, [mockElectionResult31, mockElectionResult32, mockElectionResult33]);

0 commit comments

Comments
 (0)