1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
import { createSlice, configureStore, PayloadAction } from "@reduxjs/toolkit";
import { useSelector, TypedUseSelectorHook } from "react-redux";
// Monday 0
// Tuesday 1
// Wednesday 2
// Thursday 3
// Friday 4
// Saturday 5
// Sunday 6
type Day = number;
export interface Task {
label: string;
// Number of milliseconds
duration: number;
}
export interface Habit {
day: Day;
tasks: Task[];
}
export interface State {
isLoading: boolean;
habits: Habit[];
}
const minute: number = 1000 * 60;
const hour: number = minute * 60;
/*******************************************************************************
* Tasks
******************************************************************************/
const jiuJitsu: Task = {
label: "Jiu Jitsu",
duration: hour,
};
const hotYoga: Task = {
label: "Hot Pod Yoga",
duration: hour,
};
const shave: Task = {
label: "Shave",
duration: 10 * minute,
};
const vacuum: Task = {
label: "Vacuum",
duration: 15 * minute,
};
const nap: Task = {
label: "Nap",
duration: hour,
};
const trimNails: Task = {
label: "Trim Nails",
duration: 5 * minute,
};
const trash: Task = {
label: "Take out trash",
duration: 5 * minute,
};
const scheduleLaundry: Task = {
label: "Schedule laundry pick-up",
duration: 5 * minute,
};
/*******************************************************************************
* Days
******************************************************************************/
const monday: Habit = {
day: 0,
tasks: [jiuJitsu],
};
const tuesday: Habit = {
day: 1,
tasks: [
{
label: "Work from 6PS",
duration: hour * 8,
},
jiuJitsu,
],
};
const wednesday: Habit = {
day: 2,
tasks: [
hotYoga,
shave,
{
label: "Clean apartment sinks",
duration: 15 * minute,
},
],
};
const thursday: Habit = {
day: 3,
tasks: [],
};
const friday: Habit = {
day: 4,
tasks: [hotYoga],
};
const saturday: Habit = {
day: 5,
tasks: [vacuum, nap],
};
const sunday: Habit = {
day: 6,
tasks: [jiuJitsu, nap, shave, trimNails, trash, scheduleLaundry],
};
/*******************************************************************************
* State
******************************************************************************/
const initialState: State = {
isLoading: true,
habits: [monday, tuesday, wednesday, thursday, friday, saturday, sunday],
};
export const { actions, reducer } = createSlice({
name: "application",
initialState,
reducers: {
toggleIsLoading: (state) => ({ ...state, isLoading: !state.isLoading }),
},
});
/**
* Defining and consuming this allows us to avoid annotating State in all of our
* selectors.
*/
export const useTypedSelector: TypedUseSelectorHook<State> = useSelector;
export default configureStore({ reducer });
|