Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions web/src/hooks/useCountdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from "react";
import { getTimeLeft } from "utils/date";
import { isUndefined } from "utils/index";

export function useCountdown(deadline?: number): number | undefined {
const [counter, setCounter] = useState<number | undefined>();
Expand All @@ -10,9 +11,10 @@ export function useCountdown(deadline?: number): number | undefined {
}
}, [deadline]);
useEffect(() => {
typeof counter !== "undefined" &&
counter > 0 &&
setTimeout(() => setCounter(counter - 1), 1000);
if (!isUndefined(counter) && counter > 0) {
const timeout = setTimeout(() => setCounter(counter - 1), 1000);
return () => clearTimeout(timeout);
} else return;
}, [counter]);
return counter;
}
41 changes: 8 additions & 33 deletions web/src/pages/Cases/CaseDetails/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,23 @@ const Timeline: React.FC<{
dispute: DisputeDetailsQuery["dispute"];
currentPeriodIndex: number;
}> = ({ currentPeriodIndex, dispute }) => {
const currentItemIndex = currentPeriodToCurrentItem(
currentPeriodIndex,
dispute?.ruled
);
const currentItemIndex = currentPeriodToCurrentItem(currentPeriodIndex, dispute?.ruled);
const items = useTimeline(dispute, currentItemIndex, currentItemIndex);
return (
<TimeLineContainer>
<StyledSteps
horizontal
{...{ items, currentItemIndex, currentPeriodIndex }}
/>
<StyledSteps horizontal {...{ items, currentItemIndex, currentPeriodIndex }} />
</TimeLineContainer>
);
};

const currentPeriodToCurrentItem = (
currentPeriodIndex: number,
ruled?: boolean
): number => {
const currentPeriodToCurrentItem = (currentPeriodIndex: number, ruled?: boolean): number => {
if (currentPeriodIndex <= Periods.commit) return currentPeriodIndex;
else if (currentPeriodIndex < Periods.execution)
return currentPeriodIndex - 1;
else if (currentPeriodIndex < Periods.execution) return currentPeriodIndex - 1;
else return ruled ? 5 : currentPeriodIndex - 1;
};

const useTimeline = (
dispute: DisputeDetailsQuery["dispute"],
currentItemIndex: number,
currentPeriodIndex: number
) => {
const titles = [
"Evidence Period",
"Voting Period",
"Appeal Period",
"Executed",
];
const useTimeline = (dispute: DisputeDetailsQuery["dispute"], currentItemIndex: number, currentPeriodIndex: number) => {
const titles = ["Evidence Period", "Voting Period", "Appeal Period", "Executed"];
const deadlineCurrentPeriod = getDeadline(
currentPeriodIndex,
dispute?.lastPeriodChange,
Expand Down Expand Up @@ -77,15 +58,9 @@ const getDeadline = (
lastPeriodChange?: string,
timesPerPeriod?: string[]
): number | undefined => {
if (
lastPeriodChange &&
timesPerPeriod &&
currentPeriodIndex < timesPerPeriod.length
) {
if (lastPeriodChange && timesPerPeriod && currentPeriodIndex < timesPerPeriod.length) {
const parsedLastPeriodChange = parseInt(lastPeriodChange, 10);
const parsedTimeCurrentPeriod = parseInt(
timesPerPeriod[currentPeriodIndex]
);
const parsedTimeCurrentPeriod = parseInt(timesPerPeriod[currentPeriodIndex]);
return parsedLastPeriodChange + parsedTimeCurrentPeriod;
}
return 0;
Expand Down