|
@@ -7,28 +7,54 @@ export const defaultState = {
|
|
|
to: null,
|
|
to: null,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+export const getInitialState = (): State => {
|
|
|
|
|
+ const now = new Date();
|
|
|
|
|
+ const dayNum = now.getDate();
|
|
|
|
|
+ const day = `${now.getFullYear()}-${now.getMonth() + 1}-${
|
|
|
|
|
+ dayNum < 10 ? `0${dayNum}` : dayNum
|
|
|
|
|
+ }`;
|
|
|
|
|
+ return {
|
|
|
|
|
+ sector: null,
|
|
|
|
|
+ year: now.getFullYear().toString(),
|
|
|
|
|
+ from: day,
|
|
|
|
|
+ to: day,
|
|
|
|
|
+ };
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// Sector = Station
|
|
|
export type State = {
|
|
export type State = {
|
|
|
- to?: string | null;
|
|
|
|
|
- from?: string | null;
|
|
|
|
|
- year?: string | null;
|
|
|
|
|
|
|
+ sector: string | null;
|
|
|
|
|
+ to: string;
|
|
|
|
|
+ from: string;
|
|
|
|
|
+ year: string;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const fixYear = (year: string, dateString: string) =>
|
|
|
|
|
+ `${year}-${dateString.slice(5)}`;
|
|
|
|
|
+
|
|
|
const reducer: Reducer<State, Action> = (state, action) => {
|
|
const reducer: Reducer<State, Action> = (state, action) => {
|
|
|
switch (action.type) {
|
|
switch (action.type) {
|
|
|
|
|
+ case "SET_SECTOR":
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...state,
|
|
|
|
|
+ sector: action.sector!,
|
|
|
|
|
+ };
|
|
|
case "SET_TO_CONTROL":
|
|
case "SET_TO_CONTROL":
|
|
|
return {
|
|
return {
|
|
|
...state,
|
|
...state,
|
|
|
- to: action.to,
|
|
|
|
|
|
|
+ to: fixYear(state.year, action.to!),
|
|
|
};
|
|
};
|
|
|
case "SET_FROM_CONTROL":
|
|
case "SET_FROM_CONTROL":
|
|
|
return {
|
|
return {
|
|
|
...state,
|
|
...state,
|
|
|
- from: action.from,
|
|
|
|
|
|
|
+ from: fixYear(state.year, action.from!),
|
|
|
};
|
|
};
|
|
|
case "SET_YEAR_CONTROL":
|
|
case "SET_YEAR_CONTROL":
|
|
|
return {
|
|
return {
|
|
|
...state,
|
|
...state,
|
|
|
- year: action.year,
|
|
|
|
|
|
|
+ year: action.year!,
|
|
|
|
|
+ to: fixYear(action.year!, state.to),
|
|
|
|
|
+ from: fixYear(action.year!, state.from),
|
|
|
};
|
|
};
|
|
|
default:
|
|
default:
|
|
|
return state;
|
|
return state;
|