@@ -4,7 +4,7 @@ import { Periods } from "consts/periods";
44import { DisputeDetailsQuery } from "queries/useDisputeDetailsQuery" ;
55import { Box , Steps } from "@kleros/ui-components-library" ;
66import { useCountdown } from "hooks/useCountdown" ;
7- import { secondsToDayHourMinute , getTimeLeft } from "utils/date" ;
7+ import { secondsToDayHourMinute } from "utils/date" ;
88
99const Timeline : React . FC < {
1010 dispute : DisputeDetailsQuery [ "dispute" ] ;
@@ -32,7 +32,7 @@ const currentPeriodToCurrentItem = (
3232 if ( currentPeriodIndex <= Periods . commit ) return currentPeriodIndex ;
3333 else if ( currentPeriodIndex < Periods . execution )
3434 return currentPeriodIndex - 1 ;
35- else return ruled ? currentPeriodIndex : currentPeriodIndex - 1 ;
35+ else return ruled ? 5 : currentPeriodIndex - 1 ;
3636} ;
3737
3838const useTimeline = (
@@ -46,31 +46,51 @@ const useTimeline = (
4646 "Appeal Period" ,
4747 "Executed" ,
4848 ] ;
49- const parsedLastPeriodChange = parseInt ( dispute ?. lastPeriodChange , 10 ) ;
50- const parsedTimeCurrentPeriod =
51- dispute && dispute ?. court . timesPerPeriod . length > currentPeriodIndex
52- ? parseInt ( dispute ?. court . timesPerPeriod [ currentPeriodIndex ] )
53- : 0 ;
54- const countdown = useCountdown (
55- parsedLastPeriodChange + parsedTimeCurrentPeriod
49+ const deadlineCurrentPeriod = getDeadline (
50+ currentPeriodIndex ,
51+ dispute ?. lastPeriodChange ,
52+ dispute ?. court . timesPerPeriod
5653 ) ;
54+ const countdown = useCountdown ( deadlineCurrentPeriod ) ;
5755 const getSubitems = ( index : number ) : string [ ] => {
58- if ( index < currentItemIndex ) {
59- return [ "Done!" ] ;
60- } else if ( index === 3 ) {
61- return currentItemIndex === 3 ? [ "Pending" ] : [ ] ;
62- } else if ( index === currentItemIndex ) {
63- return [ secondsToDayHourMinute ( countdown ) ] ;
64- } else {
65- return [ secondsToDayHourMinute ( dispute ?. court . timesPerPeriod [ index ] ) ] ;
56+ if ( typeof countdown !== "undefined" && dispute ) {
57+ if ( index < currentItemIndex ) {
58+ return [ "Done!" ] ;
59+ } else if ( index === 3 ) {
60+ return currentItemIndex === 3 ? [ "Pending" ] : [ ] ;
61+ } else if ( index === currentItemIndex ) {
62+ return [ secondsToDayHourMinute ( countdown ) ] ;
63+ } else {
64+ return [ secondsToDayHourMinute ( dispute ?. court . timesPerPeriod [ index ] ) ] ;
65+ }
6666 }
67+ return [ "Loading..." ] ;
6768 } ;
6869 return titles . map ( ( title , i ) => ( {
6970 title,
7071 subitems : getSubitems ( i ) ,
7172 } ) ) ;
7273} ;
7374
75+ const getDeadline = (
76+ currentPeriodIndex : number ,
77+ lastPeriodChange ?: string ,
78+ timesPerPeriod ?: string [ ]
79+ ) : number | undefined => {
80+ if (
81+ lastPeriodChange &&
82+ timesPerPeriod &&
83+ currentPeriodIndex < timesPerPeriod . length
84+ ) {
85+ const parsedLastPeriodChange = parseInt ( lastPeriodChange , 10 ) ;
86+ const parsedTimeCurrentPeriod = parseInt (
87+ timesPerPeriod [ currentPeriodIndex ]
88+ ) ;
89+ return parsedLastPeriodChange + parsedTimeCurrentPeriod ;
90+ }
91+ return undefined ;
92+ } ;
93+
7494const TimeLineContainer = styled ( Box ) `
7595 width: 100%;
7696 height: 100px;
0 commit comments