@@ -22,7 +22,7 @@ import { ScrollButtons } from './ScrollButtons';
22
22
import { TimelineRow , TimelineRowSkeleton } from './TimelineRow' ;
23
23
import { ZoomLevelPicker } from './ZoomLevelPicker' ;
24
24
import { useInfotrygdPeriods } from './hooks/useInfotrygdPeriods' ;
25
- import { ZoomLevel , useTimelineControls } from './hooks/useTimelineControls' ;
25
+ import { ZoomLevel , getMergedPeriods , useLatestPossibleDate , useTimelineControls } from './hooks/useTimelineControls' ;
26
26
27
27
import styles from './Timeline.module.css' ;
28
28
@@ -33,6 +33,14 @@ interface TimelineWithContentProps {
33
33
person : PersonFragment ;
34
34
}
35
35
36
+ const useLatestDate = (
37
+ arbeidsgivere : Array < ArbeidsgiverFragment > ,
38
+ infotrygdutbetalinger : Array < Infotrygdutbetaling > ,
39
+ ) : dayjs . Dayjs => {
40
+ const perioder = getMergedPeriods ( arbeidsgivere , infotrygdutbetalinger ) ;
41
+ return useLatestPossibleDate ( perioder ) ;
42
+ } ;
43
+
36
44
const TimelineWithContent = ( {
37
45
arbeidsgivere,
38
46
infotrygdutbetalinger,
@@ -48,13 +56,13 @@ const TimelineWithContent = ({
48
56
canNavigateForwards,
49
57
canNavigateBackwards,
50
58
} = useTimelineControls ( arbeidsgivere , infotrygdutbetalinger ) ;
59
+ const nyesteDag = useLatestDate ( arbeidsgivere , infotrygdutbetalinger ) ;
51
60
52
61
useEffect ( ( ) => {
53
62
const defaultZoomLevel = ( ) => {
54
63
if ( isBeregnetPeriode ( activePeriod ) ) {
55
- if ( dayjs ( activePeriod . fom ) . isSameOrBefore ( dayjs ( Date . now ( ) ) . subtract ( 1 , 'year' ) ) )
56
- return ZoomLevel . FIRE_Ã…R ;
57
- else if ( dayjs ( activePeriod . fom ) . isSameOrBefore ( dayjs ( Date . now ( ) ) . subtract ( 6 , 'month' ) ) )
64
+ if ( dayjs ( activePeriod . fom ) . isSameOrBefore ( nyesteDag . subtract ( 1 , 'year' ) ) ) return ZoomLevel . FIRE_Ã…R ;
65
+ else if ( dayjs ( activePeriod . fom ) . isSameOrBefore ( nyesteDag . subtract ( 6 , 'month' ) ) )
58
66
return ZoomLevel . ETT_Ã…R ;
59
67
}
60
68
return ZoomLevel . SEKS_MÃ…NEDER ;
0 commit comments