From ef1f5071f4690a95f87ef09854eaaf18571ec76e Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 19 Jun 2022 11:08:44 +0300 Subject: [PATCH] Add info on when voting ends while voting --- app/routes/plus/voting/index.tsx | 63 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/app/routes/plus/voting/index.tsx b/app/routes/plus/voting/index.tsx index 4d3f63a52..1f4cbf4fd 100644 --- a/app/routes/plus/voting/index.tsx +++ b/app/routes/plus/voting/index.tsx @@ -98,15 +98,21 @@ type PlusVotingLoaderData = // voting is not active OR user is not eligible to vote | { type: "timeInfo"; - relativeTime: string; - timestamp: number; - timing: "starts" | "ends"; voted?: boolean; + timeInfo: { + timestamp: number; + timing: "starts" | "ends"; + relativeTime: string; + }; } // user can vote | { type: "voting"; usersForVoting: UsersForVoting; + votingEnds: { + timestamp: number; + relativeTime: string; + }; }; export const loader: LoaderFunction = async ({ request }) => { @@ -117,9 +123,11 @@ export const loader: LoaderFunction = async ({ request }) => { if (!isVotingActive()) { return json({ type: "timeInfo", - relativeTime: formatDistance(startDate, now, { addSuffix: true }), - timestamp: startDate.getTime(), - timing: "starts", + timeInfo: { + relativeTime: formatDistance(startDate, now, { addSuffix: true }), + timestamp: startDate.getTime(), + timing: "starts", + }, }); } @@ -132,16 +140,22 @@ export const loader: LoaderFunction = async ({ request }) => { if (!usersForVoting || hasVoted) { return json({ type: "timeInfo", - relativeTime: formatDistance(endDate, now, { addSuffix: true }), - timestamp: endDate.getTime(), - timing: "ends", voted: hasVoted, + timeInfo: { + relativeTime: formatDistance(endDate, now, { addSuffix: true }), + timestamp: endDate.getTime(), + timing: "ends", + }, }); } return json({ type: "voting", usersForVoting, + votingEnds: { + timestamp: endDate.getTime(), + relativeTime: formatDistance(endDate, now, { addSuffix: true }), + }, }); }; @@ -172,11 +186,11 @@ function VotingTimingInfo( ) : null}
- {data.timing === "starts" + {data.timeInfo.timing === "starts" ? "Next voting starts" : "Voting is currently happening. Ends"}{" "} - - {data.relativeTime} + + {data.timeInfo.relativeTime}
@@ -189,7 +203,6 @@ const tips = [ "You +1 yourself automatically", ]; -// xxx: should display how long there is left until the voting ends function Voting(data: Extract) { const [randomTip] = React.useState(tips[Math.floor(Math.random() * 3)]); const { currentUser, previous, votes, addVote, undoLast, isReady, progress } = @@ -199,14 +212,22 @@ function Voting(data: Extract) { return (
- {progress ? ( - - ) : null} +
+
+ Voting ends{" "} + + {data.votingEnds.relativeTime} + +
+ {progress ? ( + + ) : null} +
{previous ? (

Previously{" "}