-
Notifications
You must be signed in to change notification settings - Fork 50
fix(web): timeline-bug-fix #2087
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,7 +68,7 @@ const Timeline: React.FC<{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| currentPeriodIndex: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }> = ({ currentPeriodIndex, dispute }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const currentItemIndex = currentPeriodToCurrentItem(currentPeriodIndex, dispute?.court.hiddenVotes); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const items = useTimeline(dispute, currentItemIndex, currentItemIndex); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const items = useTimeline(dispute, currentPeriodIndex); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <TimeLineContainer> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,41 +103,43 @@ const currentPeriodToCurrentItem = (currentPeriodIndex: number, hiddenVotes?: bo | |||||||||||||||||||||||||||||||||||||||||||||||||
| else return currentPeriodIndex - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const useTimeline = (dispute: DisputeDetailsQuery["dispute"], currentItemIndex: number, currentPeriodIndex: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const useTimeline = (dispute: DisputeDetailsQuery["dispute"], currentPeriodIndex: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const isDesktop = useIsDesktop(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const titles = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const titles = ["Evidence", "Voting", "Appeal", "Executed"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (dispute?.court.hiddenVotes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| titles.splice(1, 0, "Commit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return titles; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [dispute]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const titles = ["Evidence", "Commit", "Voting", "Appeal", "Executed"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const deadlineCurrentPeriod = getDeadline( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| currentPeriodIndex, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dispute?.lastPeriodChange, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| dispute?.court.timesPerPeriod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| const countdown = useCountdown(deadlineCurrentPeriod); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const getSubitems = (index: number): string[] | React.ReactNode[] => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof countdown !== "undefined" && dispute) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (index === titles.length - 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index === currentItemIndex && countdown === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index === currentPeriodIndex && countdown === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return ["Time's up!"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index < currentItemIndex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index < currentPeriodIndex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index === currentItemIndex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (index === currentPeriodIndex) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return [secondsToDayHourMinute(countdown)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
117
to
129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix type mismatch and potential NaN in future-period subitems secondsToDayHourMinute expects a number, but dispute?.court.timesPerPeriod[index] is typed as string | undefined. This can produce type errors and NaN at runtime when values are undefined or non-numeric. Parse the value and provide a safe default. Apply this diff: - } else {
- return [secondsToDayHourMinute(dispute?.court.timesPerPeriod[index])];
- }
+ } else {
+ const raw = dispute?.court.timesPerPeriod?.[index];
+ const periodSeconds = Number(raw ?? 0);
+ return [secondsToDayHourMinute(periodSeconds)];
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return [<StyledSkeleton key={index} width={60} />]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return titles.map((title, i) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| title: i + 1 < titles.length && isDesktop ? `${title} Period` : title, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subitems: getSubitems(i), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return titles.flatMap((title, i) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // if not hidden votes, skip commit index | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!dispute?.court.hiddenVotes && i === Periods.commit) return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| title: i + 1 < titles.length && isDesktop ? `${title} Period` : title, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| subitems: getSubitems(i), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getDeadline = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Clamp “Time’s up!” condition to countdown <= 0 to avoid negative durations
If useCountdown ever returns negative values after the deadline, the UI could show negative durations instead of “Time’s up!”. Using <= 0 is safer and avoids transient negative subitems.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents