Skip to content

Commit

Permalink
fix: sometimes wrongly display the round state
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Jul 10, 2024
1 parent b747b50 commit 04e2b12
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ export const Info = ({ size, showVotingInfo = false }: InfoProps): JSX.Element =
const steps = [
{
label: "application",
state: EAppState.APPLICATION,
start: config.startsAt,
end: config.registrationEndsAt,
},
{
label: "voting",
state: EAppState.VOTING,
start: config.registrationEndsAt,
end: votingEndsAt,
},
{
label: "tallying",
state: EAppState.TALLYING,
start: votingEndsAt,
end: config.resultsAt,
},
{
label: "results",
state: EAppState.RESULTS,
start: config.resultsAt,
end: config.resultsAt,
},
Expand All @@ -74,7 +78,7 @@ export const Info = ({ size, showVotingInfo = false }: InfoProps): JSX.Element =
key={step.label}
end={step.end}
start={step.start}
state={defineState({ start: step.start, end: step.end })}
state={defineState({ state: step.state, appState })}
title={step.label}
/>
),
Expand All @@ -84,14 +88,16 @@ export const Info = ({ size, showVotingInfo = false }: InfoProps): JSX.Element =
);
};

function defineState({ start, end }: { start: Date; end: Date }): EInfoCardState {
const now = new Date();
function defineState({ state, appState }: { state: EAppState; appState: EAppState }): EInfoCardState {
const statesOrder = [EAppState.APPLICATION, EAppState.VOTING, EAppState.TALLYING, EAppState.RESULTS];
const currentStateOrder = statesOrder.indexOf(state);
const appStateOrder = statesOrder.indexOf(appState);

if (end < now) {
if (currentStateOrder < appStateOrder) {
return EInfoCardState.PASSED;
}

if (end > now && start < now) {
if (currentStateOrder === appStateOrder) {
return EInfoCardState.ONGOING;
}

Expand Down

0 comments on commit 04e2b12

Please sign in to comment.