@@ -14,21 +14,14 @@ const localizer = dayjsLocalizer(dayjs);
14
14
class Map extends Component {
15
15
onRangeChange = range => {
16
16
let from , to ;
17
-
18
17
if ( Array . isArray ( range ) ) {
19
- from = dayjs ( range [ 0 ] )
20
- . subtract ( 7 , 'day' )
21
- . toDate ( ) ;
18
+ from = dayjs ( range [ 0 ] ) . toDate ( ) ;
22
19
to = dayjs ( range [ range . length - 1 ] )
23
- . add ( 7 , 'day' )
20
+ . add ( 1 , 'day' )
24
21
. toDate ( ) ;
25
22
} else {
26
- from = dayjs ( range . start )
27
- . subtract ( 7 , 'day' )
28
- . toDate ( ) ;
29
- to = dayjs ( range . end )
30
- . add ( 7 , 'day' )
31
- . toDate ( ) ;
23
+ from = dayjs ( range . start ) . toDate ( ) ;
24
+ to = dayjs ( range . end ) . toDate ( ) ;
32
25
}
33
26
this . props . getEventsInRange ( from , to ) ;
34
27
} ;
@@ -41,17 +34,48 @@ class Map extends Component {
41
34
}
42
35
} ;
43
36
37
+ onViewChange = newView => {
38
+ localStorage . setItem ( 'calendar_last_view' , newView ) ;
39
+ } ;
40
+
44
41
componentWillMount ( ) {
45
42
dayjs . locale ( this . props . user . language ) ;
46
43
47
- const from = dayjs ( )
44
+ let from = dayjs ( )
48
45
. startOf ( 'week' )
49
- . subtract ( 7 , 'day' )
46
+ . subtract ( 1 , 'day' )
50
47
. toDate ( ) ;
51
- const to = dayjs ( )
48
+ let to = dayjs ( )
52
49
. endOf ( 'week' )
53
- . add ( 7 , 'day' )
50
+ . add ( 1 , 'day' )
54
51
. toDate ( ) ;
52
+
53
+ switch ( localStorage . getItem ( 'calendar_last_view' ) ) {
54
+ case 'month' :
55
+ from = dayjs ( )
56
+ . startOf ( 'month' )
57
+ . subtract ( 7 , 'day' )
58
+ . toDate ( ) ;
59
+ to = dayjs ( )
60
+ . endOf ( 'month' )
61
+ . add ( 7 , 'day' )
62
+ . toDate ( ) ;
63
+ break ;
64
+ case 'day' :
65
+ from = dayjs ( )
66
+ . subtract ( 1 , 'day' )
67
+ . toDate ( ) ;
68
+ to = dayjs ( )
69
+ . add ( 1 , 'day' )
70
+ . toDate ( ) ;
71
+ break ;
72
+ case 'agenda' :
73
+ from = dayjs ( ) . toDate ( ) ;
74
+ to = dayjs ( )
75
+ . add ( 1 , 'month' )
76
+ . toDate ( ) ;
77
+ break ;
78
+ }
55
79
this . props . getEventsInRange ( from , to ) ;
56
80
}
57
81
@@ -79,7 +103,8 @@ class Map extends Component {
79
103
} }
80
104
popup
81
105
onRangeChange = { this . onRangeChange }
82
- defaultView = "week"
106
+ defaultView = { localStorage . getItem ( 'calendar_last_view' ) || 'week' }
107
+ onView = { this . onViewChange }
83
108
culture = { props . user . language }
84
109
messages = { this . props . intl . dictionary . calendar }
85
110
scrollToTime = { dayjs ( )
0 commit comments