@colisweb/rescript-toolkit 4.10.0 → 4.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ open ReactIntl
|
|
|
2
2
|
|
|
3
3
|
type rec state = {
|
|
4
4
|
period: period,
|
|
5
|
-
selectedDay:
|
|
5
|
+
selectedDay: Js.Date.t,
|
|
6
6
|
}
|
|
7
7
|
and period = {
|
|
8
8
|
start: Js.Date.t,
|
|
@@ -12,7 +12,7 @@ and period = {
|
|
|
12
12
|
type action =
|
|
13
13
|
| PreviousPeriod
|
|
14
14
|
| NextPeriod
|
|
15
|
-
| UpdateSelectedDay(
|
|
15
|
+
| UpdateSelectedDay(Js.Date.t)
|
|
16
16
|
|
|
17
17
|
let updateQueryParams = (state: state) => {
|
|
18
18
|
RescriptReactRouter.replace(
|
|
@@ -45,11 +45,11 @@ let make = (
|
|
|
45
45
|
~selectedDay: option<Js.Date.t>=?,
|
|
46
46
|
~className="",
|
|
47
47
|
~counters: option<dayCounter>=?,
|
|
48
|
+
~periodLength=7,
|
|
48
49
|
~children,
|
|
49
50
|
) => {
|
|
50
51
|
let {isSm} = Toolkit__Hooks.useMediaQuery()
|
|
51
52
|
|
|
52
|
-
let periodLength = isSm ? 7 : 3
|
|
53
53
|
let ({period, selectedDay}, dispatch) = ReactUpdate.useReducerWithMapState(
|
|
54
54
|
(state, action) =>
|
|
55
55
|
switch action {
|
|
@@ -60,9 +60,7 @@ let make = (
|
|
|
60
60
|
start: state.period.start->DateFns.subDays(periodLength)->DateFns.startOfDay,
|
|
61
61
|
end_: state.period.start->DateFns.subDays(1),
|
|
62
62
|
},
|
|
63
|
-
selectedDay: state.
|
|
64
|
-
state.period.start->DateFns.subDays(periodLength)->DateFns.startOfDay
|
|
65
|
-
),
|
|
63
|
+
selectedDay: state.period.start->DateFns.subDays(periodLength)->DateFns.startOfDay,
|
|
66
64
|
},
|
|
67
65
|
({state}) => {
|
|
68
66
|
updateQueryParams(state)
|
|
@@ -77,7 +75,7 @@ let make = (
|
|
|
77
75
|
start: state.period.end_->DateFns.addDays(1),
|
|
78
76
|
end_: state.period.end_->DateFns.addDays(periodLength),
|
|
79
77
|
},
|
|
80
|
-
selectedDay: state.
|
|
78
|
+
selectedDay: state.period.end_->DateFns.addDays(1),
|
|
81
79
|
},
|
|
82
80
|
({state}) => {
|
|
83
81
|
updateQueryParams(state)
|
|
@@ -113,11 +111,9 @@ let make = (
|
|
|
113
111
|
start,
|
|
114
112
|
end_: start->DateFns.addDays(periodLength - 1),
|
|
115
113
|
}),
|
|
116
|
-
selectedDay: selectedDay->Option.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
? None
|
|
120
|
-
: Some(startOfWeek->Option.getWithDefault(defaultPeriod.start)),
|
|
114
|
+
selectedDay: selectedDay->Option.getWithDefault(
|
|
115
|
+
startOfWeek->Option.getWithDefault(defaultPeriod.start),
|
|
116
|
+
),
|
|
121
117
|
}
|
|
122
118
|
},
|
|
123
119
|
)
|
|
@@ -142,8 +138,8 @@ let make = (
|
|
|
142
138
|
let formattedDay =
|
|
143
139
|
intl->Intl.formatDateWithOptions(day, dateTimeFormatOptions(~weekday=#long, ()))
|
|
144
140
|
|
|
145
|
-
let isSelected =
|
|
146
|
-
|
|
141
|
+
let isSelected = DateFns.isSameDay(selectedDay, day)
|
|
142
|
+
|
|
147
143
|
<React.Fragment key={i->Int.toString ++ "-day"}>
|
|
148
144
|
{i == 0 || day->DateFns.isFirstDayOfMonth
|
|
149
145
|
? <p className="text-xs text-neutral-700 uppercase">
|
|
@@ -151,7 +147,7 @@ let make = (
|
|
|
151
147
|
</p>
|
|
152
148
|
: React.null}
|
|
153
149
|
<div
|
|
154
|
-
onClick={_ => dispatch(UpdateSelectedDay(
|
|
150
|
+
onClick={_ => dispatch(UpdateSelectedDay(day))}
|
|
155
151
|
className="flex flex-col items-stretch w-16 mx-1 font-display">
|
|
156
152
|
<p
|
|
157
153
|
className={cx([
|