@learnpack/learnpack 5.0.288 → 5.0.291

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.
@@ -1,223 +1,222 @@
1
- import { create } from "zustand";
2
- import { persist } from "zustand/middleware";
3
- import { Lesson } from "../components/LessonItem";
4
- import { ParsedFile } from "../components/FileUploader";
5
- import { TMessage } from "../components/Message";
6
- // import { ParsedLink } from "../components/LinkUploader"
7
- export type TDifficulty = "easy" | "beginner" | "intermediate" | "hard";
8
-
9
- export type FormState = {
10
- description: string;
11
- duration: number;
12
- hasContentIndex: boolean;
13
- contentIndex: string;
14
- purpose: string;
15
- difficulty: TDifficulty;
16
- slug: string;
17
- language?: string;
18
- isCompleted: boolean;
19
- variables: string[];
20
- currentStep: string;
21
- title?: string;
22
- technologies?: string[];
23
- };
24
-
25
- type Auth = {
26
- bcToken: string;
27
- rigoToken: string;
28
- userId: string;
29
- user: any;
30
- publicToken: string;
31
- };
32
- export type Syllabus = {
33
- lessons: Lesson[];
34
- courseInfo: FormState;
35
- generationMode: "continue-with-all" | "next-three";
36
- // messages: TMessage[]
37
- };
38
-
39
- type Consumables = {
40
- [key: string]: number;
41
- };
42
-
43
- type TTechnology = {
44
- slug: string;
45
- lang: string;
46
- };
47
-
48
- type Store = {
49
- auth: Auth;
50
- formState: FormState;
51
- setFormState: (formState: Partial<FormState>) => void;
52
- resetFormState: () => void;
53
- setAuth: (auth: Auth) => void;
54
- // syllabus: Syllabus
55
- planToRedirect: string;
56
- setPlanToRedirect: (planToRedirect: string) => void;
57
- uploadedFiles: ParsedFile[];
58
- setUploadedFiles: (uploadedFiles: ParsedFile[]) => void;
59
- messages: TMessage[];
60
- setMessages: (
61
- messages: TMessage[] | ((prev: TMessage[]) => TMessage[])
62
- ) => void;
63
- cleanHistory: () => void;
64
- history: Syllabus[];
65
- technologies: TTechnology[];
66
- setTechnologies: (technologies: TTechnology[]) => void;
67
- undo: () => void;
68
- push: (syllabus: Syllabus) => void;
69
- cleanAll: () => void;
70
- // setSyllabus: (syllabus: Partial<Syllabus>) => void
71
- consumables: Consumables;
72
- setConsumables: (consumables: Partial<Consumables>) => void;
73
- mode: "student" | "teacher";
74
- setMode: (mode: "student" | "teacher") => void;
75
- };
76
-
77
- const useStore = create<Store>()(
78
- persist(
79
- (set) => ({
80
- auth: {
81
- bcToken: "",
82
- rigoToken: "",
83
- userId: "",
84
- user: null,
85
- publicToken: "",
86
- },
87
- planToRedirect: "learnpack-creator",
88
- setPlanToRedirect: (planToRedirect: string) => set({ planToRedirect }),
89
- formState: {
90
- description: "",
91
- duration: 0,
92
- slug: "",
93
- hasContentIndex: false,
94
- contentIndex: "",
95
- purpose: "",
96
- language: "en",
97
- technologies: [],
98
- difficulty: "beginner",
99
- // sources: [],
100
- isCompleted: false,
101
- currentStep: "description",
102
- variables: [
103
- "description",
104
- "duration",
105
- "purpose",
106
- "hasContentIndex",
107
- "verifyHuman",
108
- ],
109
- },
110
- messages: [],
111
- technologies: [],
112
- setTechnologies: (technologies: TTechnology[]) => set({ technologies }),
113
- setMessages: (
114
- messages: TMessage[] | ((prev: TMessage[]) => TMessage[])
115
- ) => {
116
- set((state) => ({
117
- messages:
118
- typeof messages === "function"
119
- ? messages(state.messages)
120
- : messages,
121
- }));
122
- },
123
- setFormState: (formState: Partial<FormState>) =>
124
- set((state) => ({ formState: { ...state.formState, ...formState } })),
125
- resetFormState: () =>
126
- set({
127
- formState: {
128
- slug: "",
129
- currentStep: "description",
130
- description: "",
131
- duration: 0,
132
- language: "en",
133
- difficulty: "beginner",
134
- technologies: [],
135
- hasContentIndex: false,
136
- contentIndex: "",
137
- purpose: "",
138
- isCompleted: false,
139
- variables: [
140
- "description",
141
- "duration",
142
- "purpose",
143
- "hasContentIndex",
144
- "verifyHuman",
145
- ],
146
- },
147
- }),
148
-
149
- setUploadedFiles: (uploadedFiles) =>
150
- set(() => ({
151
- uploadedFiles: [...uploadedFiles],
152
- })),
153
- uploadedFiles: [],
154
- history: [],
155
- push: (syllabus: Syllabus) => {
156
- set((state) => ({
157
- history: [...state.history, syllabus],
158
- }));
159
- },
160
-
161
- undo: () => {
162
- set((state) => {
163
- return {
164
- history: state.history.slice(0, -1),
165
- };
166
- });
167
- },
168
- cleanHistory: () => {
169
- set(() => ({ history: [] }));
170
- },
171
- cleanAll: () => {
172
- set({
173
- uploadedFiles: [],
174
- messages: [],
175
- history: [],
176
- technologies: [],
177
- formState: {
178
- description: "",
179
- duration: 0,
180
- slug: "",
181
- difficulty: "beginner",
182
- language: "en",
183
- technologies: [],
184
- hasContentIndex: false,
185
- contentIndex: "",
186
- purpose: "",
187
- isCompleted: false,
188
- variables: [
189
- "description",
190
- "duration",
191
- "purpose",
192
- "hasContentIndex",
193
- "verifyHuman",
194
- ],
195
- currentStep: "description",
196
- },
197
- });
198
- },
199
- consumables: {},
200
- setConsumables: (consumables: Partial<Consumables>) =>
201
- set((state) => {
202
- const sanitized: Consumables = Object.fromEntries(
203
- Object.entries(consumables).map(([k, v]) => [k, v ?? 0])
204
- );
205
- return {
206
- consumables: {
207
- ...state.consumables,
208
- ...sanitized,
209
- },
210
- };
211
- }),
212
-
213
- setAuth: (auth: Auth) => set({ auth }),
214
- mode: "student",
215
- setMode: (mode: "student" | "teacher") => set({ mode }),
216
- }),
217
- {
218
- name: "syllabus-storage",
219
- }
220
- )
221
- );
222
-
223
- export default useStore;
1
+ import { create } from "zustand"
2
+ import { persist } from "zustand/middleware"
3
+ import { Lesson } from "../components/LessonItem"
4
+ import { ParsedFile } from "../components/FileUploader"
5
+ import { TMessage } from "../components/Message"
6
+ // import { ParsedLink } from "../components/LinkUploader"
7
+ export type TDifficulty = "easy" | "beginner" | "intermediate" | "hard"
8
+
9
+ export type FormState = {
10
+ description: string
11
+ duration: number
12
+ hasContentIndex: boolean
13
+ contentIndex: string
14
+ purpose: string
15
+ difficulty: TDifficulty
16
+ slug: string
17
+ language?: string
18
+ isCompleted: boolean
19
+ variables: string[]
20
+ currentStep: string
21
+ title?: string
22
+ technologies?: string[]
23
+ }
24
+
25
+ type Auth = {
26
+ bcToken: string
27
+ rigoToken: string
28
+ userId: string
29
+ user: any
30
+ publicToken: string
31
+ }
32
+ export type Syllabus = {
33
+ lessons: Lesson[]
34
+ courseInfo: FormState
35
+ // messages: TMessage[]
36
+ }
37
+
38
+ type Consumables = {
39
+ [key: string]: number
40
+ }
41
+
42
+ type TTechnology = {
43
+ slug: string
44
+ lang: string
45
+ }
46
+
47
+ type Store = {
48
+ auth: Auth
49
+ formState: FormState
50
+ setFormState: (formState: Partial<FormState>) => void
51
+ resetFormState: () => void
52
+ setAuth: (auth: Auth) => void
53
+ // syllabus: Syllabus
54
+ planToRedirect: string
55
+ setPlanToRedirect: (planToRedirect: string) => void
56
+ uploadedFiles: ParsedFile[]
57
+ setUploadedFiles: (uploadedFiles: ParsedFile[]) => void
58
+ messages: TMessage[]
59
+ setMessages: (
60
+ messages: TMessage[] | ((prev: TMessage[]) => TMessage[])
61
+ ) => void
62
+ cleanHistory: () => void
63
+ history: Syllabus[]
64
+ technologies: TTechnology[]
65
+ setTechnologies: (technologies: TTechnology[]) => void
66
+ undo: () => void
67
+ push: (syllabus: Syllabus) => void
68
+ cleanAll: () => void
69
+ // setSyllabus: (syllabus: Partial<Syllabus>) => void
70
+ consumables: Consumables
71
+ setConsumables: (consumables: Partial<Consumables>) => void
72
+ mode: "student" | "teacher"
73
+ setMode: (mode: "student" | "teacher") => void
74
+ }
75
+
76
+ const useStore = create<Store>()(
77
+ persist(
78
+ (set) => ({
79
+ auth: {
80
+ bcToken: "",
81
+ rigoToken: "",
82
+ userId: "",
83
+ user: null,
84
+ publicToken: "",
85
+ },
86
+ planToRedirect: "learnpack-creator",
87
+ setPlanToRedirect: (planToRedirect: string) => set({ planToRedirect }),
88
+ formState: {
89
+ description: "",
90
+ duration: 0,
91
+ slug: "",
92
+ hasContentIndex: false,
93
+ contentIndex: "",
94
+ purpose: "",
95
+ language: "en",
96
+ technologies: [],
97
+ difficulty: "beginner",
98
+ // sources: [],
99
+ isCompleted: false,
100
+ currentStep: "description",
101
+ variables: [
102
+ "description",
103
+ "duration",
104
+ "purpose",
105
+ "hasContentIndex",
106
+ "verifyHuman",
107
+ ],
108
+ },
109
+ messages: [],
110
+ technologies: [],
111
+ setTechnologies: (technologies: TTechnology[]) => set({ technologies }),
112
+ setMessages: (
113
+ messages: TMessage[] | ((prev: TMessage[]) => TMessage[])
114
+ ) => {
115
+ set((state) => ({
116
+ messages:
117
+ typeof messages === "function"
118
+ ? messages(state.messages)
119
+ : messages,
120
+ }))
121
+ },
122
+ setFormState: (formState: Partial<FormState>) =>
123
+ set((state) => ({ formState: { ...state.formState, ...formState } })),
124
+ resetFormState: () =>
125
+ set({
126
+ formState: {
127
+ slug: "",
128
+ currentStep: "description",
129
+ description: "",
130
+ duration: 0,
131
+ language: "en",
132
+ difficulty: "beginner",
133
+ technologies: [],
134
+ hasContentIndex: false,
135
+ contentIndex: "",
136
+ purpose: "",
137
+ isCompleted: false,
138
+ variables: [
139
+ "description",
140
+ "duration",
141
+ "purpose",
142
+ "hasContentIndex",
143
+ "verifyHuman",
144
+ ],
145
+ },
146
+ }),
147
+
148
+ setUploadedFiles: (uploadedFiles) =>
149
+ set(() => ({
150
+ uploadedFiles: [...uploadedFiles],
151
+ })),
152
+ uploadedFiles: [],
153
+ history: [],
154
+ push: (syllabus: Syllabus) => {
155
+ set((state) => ({
156
+ history: [...state.history, syllabus],
157
+ }))
158
+ },
159
+
160
+ undo: () => {
161
+ set((state) => {
162
+ return {
163
+ history: state.history.slice(0, -1),
164
+ }
165
+ })
166
+ },
167
+ cleanHistory: () => {
168
+ set(() => ({ history: [] }))
169
+ },
170
+ cleanAll: () => {
171
+ set({
172
+ uploadedFiles: [],
173
+ messages: [],
174
+ history: [],
175
+ technologies: [],
176
+ formState: {
177
+ description: "",
178
+ duration: 0,
179
+ slug: "",
180
+ difficulty: "beginner",
181
+ language: "en",
182
+ technologies: [],
183
+ hasContentIndex: false,
184
+ contentIndex: "",
185
+ purpose: "",
186
+ isCompleted: false,
187
+ variables: [
188
+ "description",
189
+ "duration",
190
+ "purpose",
191
+ "hasContentIndex",
192
+ "verifyHuman",
193
+ ],
194
+ currentStep: "description",
195
+ },
196
+ })
197
+ },
198
+ consumables: {},
199
+ setConsumables: (consumables: Partial<Consumables>) =>
200
+ set((state) => {
201
+ const sanitized: Consumables = Object.fromEntries(
202
+ Object.entries(consumables).map(([k, v]) => [k, v ?? 0])
203
+ )
204
+ return {
205
+ consumables: {
206
+ ...state.consumables,
207
+ ...sanitized,
208
+ },
209
+ }
210
+ }),
211
+
212
+ setAuth: (auth: Auth) => set({ auth }),
213
+ mode: "student",
214
+ setMode: (mode: "student" | "teacher") => set({ mode }),
215
+ }),
216
+ {
217
+ name: "syllabus-storage",
218
+ }
219
+ )
220
+ )
221
+
222
+ export default useStore