Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrongly display the round state #202

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading