-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseStore.js
More file actions
96 lines (75 loc) · 2.64 KB
/
useStore.js
File metadata and controls
96 lines (75 loc) · 2.64 KB
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
import { create } from "zustand";
const useStore = create((set) => ({
//theme
theme: "night",
setTheme: (theme) => set({ theme }),
//InputStats
activeTab: "lifts",
setActiveTab: (value) => set({ activeTab: value }),
activeNav: false,
setActiveNav: (value) => set({ activeNav: value }),
userData: [
{ month: 'Jan', weight: 0 },
{ month: 'Feb', weight: 0 },
{ month: 'Mar', weight: 0 },
{ month: 'Apr', weight: 0 },
{ month: 'May', weight: 0 },
{ month: 'Jun', weight: 0 },
{ month: 'Jul', weight: 0 },
{ month: 'Aug', weight: 0 },
{ month: 'Sep', weight: 0 },
{ month: 'Oct', weight: 0 },
{ month: 'Nov', weight: 0 },
{ month: 'Dec', weight: 0 },
],
setUserData: (weightProvided, index) => set((state) => ({
userData: state.userData.map((month, i) =>
i === index ? { ...month, weight: weightProvided } : month
)
})),
exercisesData: [],
setExercisesData: (exercisesData) => set({ exercisesData }),
exerciseSelected: 'Select an exercise',
setExerciseSelected: (exerciseSelected) => set({ exerciseSelected }),
showCalendar: false,
setShowCalendar: (showCalendar) => set({ showCalendar }),
calendarValue: "Input your lifts",
setCalendarValue: (calendarValue) => set({ calendarValue }),
calendarError: false,
setCalendarError: (calendarError) => set({ calendarError }),
showExercises: false,
setShowExercises: (showExercises) => set({ showExercises }),
showMultipleExercises: false,
setShowMultipleExercises: (showMultipleExercises) => set({ showMultipleExercises }),
showCharts: false,
setShowCharts: (showCharts) => set({ showCharts }),
chartType: null,
setChartType: (value) => set({ chartType: value }),
numberOfExercises: 2,
setNumberOfExercises: (numberOfExercises) => set({ numberOfExercises }),
toggleCalendar: () => set(state => ({ showCalendar: !state.showCalendar })),
toggleExercises: () => set(state => ({ showExercises: !state.showExercises })),
toggleCharts: () => set(state => ({ showCharts: !state.showCharts })),
toggleMultipleExercises: () => {
set(state => ({
showMultipleExercises: !state.showMultipleExercises,
exercisesData: []
}));
},
calendarSubmit: () => {
set(state => {
let lifts = state.userData.filter(data => data.weight > 0).length;
if (lifts >= 3) {
sessionStorage.setItem("userDataStrength", JSON.stringify(state.userData));
return {
calendarValue: "Lifts Updated",
calendarError: false,
showCalendar: !state.showCalendar
};
} else {
return { calendarError: true };
}
});
}
}));
export { useStore };