Skip to content

Commit 0de7638

Browse files
committed
Save last calendar view
1 parent 1f7617c commit 0de7638

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

front/src/routes/calendar/index.js

+41-16
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,14 @@ const localizer = dayjsLocalizer(dayjs);
1414
class Map extends Component {
1515
onRangeChange = range => {
1616
let from, to;
17-
1817
if (Array.isArray(range)) {
19-
from = dayjs(range[0])
20-
.subtract(7, 'day')
21-
.toDate();
18+
from = dayjs(range[0]).toDate();
2219
to = dayjs(range[range.length - 1])
23-
.add(7, 'day')
20+
.add(1, 'day')
2421
.toDate();
2522
} 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();
3225
}
3326
this.props.getEventsInRange(from, to);
3427
};
@@ -41,17 +34,48 @@ class Map extends Component {
4134
}
4235
};
4336

37+
onViewChange = newView => {
38+
localStorage.setItem('calendar_last_view', newView);
39+
};
40+
4441
componentWillMount() {
4542
dayjs.locale(this.props.user.language);
4643

47-
const from = dayjs()
44+
let from = dayjs()
4845
.startOf('week')
49-
.subtract(7, 'day')
46+
.subtract(1, 'day')
5047
.toDate();
51-
const to = dayjs()
48+
let to = dayjs()
5249
.endOf('week')
53-
.add(7, 'day')
50+
.add(1, 'day')
5451
.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+
}
5579
this.props.getEventsInRange(from, to);
5680
}
5781

@@ -79,7 +103,8 @@ class Map extends Component {
79103
}}
80104
popup
81105
onRangeChange={this.onRangeChange}
82-
defaultView="week"
106+
defaultView={localStorage.getItem('calendar_last_view') || 'week'}
107+
onView={this.onViewChange}
83108
culture={props.user.language}
84109
messages={this.props.intl.dictionary.calendar}
85110
scrollToTime={dayjs()

0 commit comments

Comments
 (0)