@learnpack/learnpack 5.0.309 → 5.0.310
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/README.md +409 -409
- package/lib/commands/audit.js +15 -15
- package/lib/commands/breakToken.js +19 -19
- package/lib/commands/clean.js +3 -3
- package/lib/commands/logout.js +3 -3
- package/lib/commands/serve.js +16 -16
- package/lib/creatorDist/assets/{index-B37w_ZhT.js → index-BI7U47zy.js} +13186 -13013
- package/lib/creatorDist/index.html +1 -1
- package/lib/managers/config/index.js +77 -77
- package/lib/utils/creatorUtilities.js +14 -14
- package/lib/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
- package/lib/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
- package/lib/utils/templates/scorm/adlcp_rootv1p2.xsd +110 -110
- package/lib/utils/templates/scorm/config/index.html +209 -209
- package/lib/utils/templates/scorm/ims_xml.xsd +1 -1
- package/lib/utils/templates/scorm/imscp_rootv1p1p2.xsd +345 -345
- package/lib/utils/templates/scorm/imsmanifest.xml +38 -38
- package/lib/utils/templates/scorm/imsmd_rootv1p2p1.xsd +573 -573
- package/package.json +1 -1
- package/src/commands/audit.ts +487 -487
- package/src/commands/breakToken.ts +67 -67
- package/src/commands/clean.ts +30 -30
- package/src/commands/logout.ts +38 -38
- package/src/commands/publish.ts +517 -517
- package/src/commands/serve.ts +3179 -3179
- package/src/commands/start.ts +333 -333
- package/src/commands/translate.ts +123 -123
- package/src/creator/README.md +54 -54
- package/src/creator/package-lock.json +6621 -6621
- package/src/creator/package.json +55 -55
- package/src/creator/src/App.tsx +611 -608
- package/src/creator/src/components/FileUploader.tsx +340 -302
- package/src/creator/src/components/Icon.tsx +18 -18
- package/src/creator/src/components/LessonItem.tsx +152 -152
- package/src/creator/src/components/Login.tsx +259 -259
- package/src/creator/src/components/ParamsChecker.tsx +25 -25
- package/src/creator/src/components/Uploader.tsx +3 -6
- package/src/creator/src/components/syllabus/ContentIndex.tsx +323 -323
- package/src/creator/src/components/syllabus/SyllabusEditor.tsx +341 -337
- package/src/creator/src/i18n.ts +28 -28
- package/src/creator/src/locales/en.json +139 -138
- package/src/creator/src/locales/es.json +139 -138
- package/src/creator/src/utils/configTypes.ts +122 -122
- package/src/creator/src/utils/constants.ts +13 -13
- package/src/creator/src/utils/creatorUtils.ts +46 -46
- package/src/creator/src/utils/eventBus.ts +2 -2
- package/src/creator/src/utils/rigo.ts +1 -1
- package/src/creator/src/utils/socket.ts +61 -61
- package/src/creator/src/utils/store.ts +222 -222
- package/src/creator/src/vite-env.d.ts +1 -1
- package/src/creator/vite.config.ts +13 -13
- package/src/creatorDist/assets/{index-B37w_ZhT.js → index-BI7U47zy.js} +13186 -13013
- package/src/creatorDist/index.html +1 -1
- package/src/managers/config/defaults.ts +49 -49
- package/src/managers/config/exercise.ts +364 -364
- package/src/managers/config/index.ts +775 -775
- package/src/managers/file.ts +236 -236
- package/src/managers/server/routes.ts +554 -554
- package/src/managers/telemetry.ts +188 -188
- package/src/models/action.ts +13 -13
- package/src/models/config-manager.ts +28 -28
- package/src/models/config.ts +106 -106
- package/src/models/exercise-obj.ts +30 -30
- package/src/models/session.ts +39 -39
- package/src/models/socket.ts +61 -61
- package/src/models/status.ts +16 -16
- package/src/ui/_app/app.css +1 -1
- package/src/ui/_app/app.js +477 -407
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/BaseCommand.ts +56 -56
- package/src/utils/api.ts +665 -665
- package/src/utils/audit.ts +392 -392
- package/src/utils/checkNotInstalled.ts +267 -267
- package/src/utils/convertCreds.js +34 -34
- package/src/utils/creatorUtilities.ts +504 -504
- package/src/utils/export/README.md +178 -178
- package/src/utils/incrementVersion.js +74 -74
- package/src/utils/misc.ts +58 -58
- package/src/utils/sidebarGenerator.ts +195 -195
- package/src/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
- package/src/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
- package/src/utils/templates/scorm/adlcp_rootv1p2.xsd +110 -110
- package/src/utils/templates/scorm/config/index.html +209 -209
- package/src/utils/templates/scorm/ims_xml.xsd +1 -1
- package/src/utils/templates/scorm/imscp_rootv1p1p2.xsd +345 -345
- package/src/utils/templates/scorm/imsmanifest.xml +38 -38
- package/src/utils/templates/scorm/imsmd_rootv1p2p1.xsd +573 -573
|
@@ -1,337 +1,341 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react"
|
|
2
|
-
import { useShallow } from "zustand/react/shallow"
|
|
3
|
-
import useStore from "../../utils/store"
|
|
4
|
-
import { publicInteractiveCreation } from "../../utils/rigo"
|
|
5
|
-
import {
|
|
6
|
-
parseLesson,
|
|
7
|
-
// useConsumableCall,
|
|
8
|
-
validateTokens,
|
|
9
|
-
checkParams,
|
|
10
|
-
loginWithToken,
|
|
11
|
-
createCourse,
|
|
12
|
-
isSlugAvailable,
|
|
13
|
-
// reWriteTitle,
|
|
14
|
-
useConsumableCall,
|
|
15
|
-
isValidRigoToken,
|
|
16
|
-
isValidPublicToken,
|
|
17
|
-
} from "../../utils/lib"
|
|
18
|
-
|
|
19
|
-
import Loader from "../Loader"
|
|
20
|
-
import { TMessage } from "../Message"
|
|
21
|
-
import { Lesson } from "../LessonItem"
|
|
22
|
-
import { ConsumablesManager } from "../ConsumablesManager"
|
|
23
|
-
import toast from "react-hot-toast"
|
|
24
|
-
import { ContentIndex } from "./ContentIndex"
|
|
25
|
-
import { Sidebar } from "./Sidebar"
|
|
26
|
-
import Login from "../Login"
|
|
27
|
-
import { useNavigate } from "react-router"
|
|
28
|
-
import { ParamsChecker } from "../ParamsChecker"
|
|
29
|
-
import { randomUUID } from "../../utils/creatorUtils"
|
|
30
|
-
import { RIGO_FLOAT_GIF } from "../../utils/constants"
|
|
31
|
-
import { useTranslation } from "react-i18next"
|
|
32
|
-
import NotificationListener from "../NotificationListener"
|
|
33
|
-
|
|
34
|
-
const SyllabusEditor: React.FC = () => {
|
|
35
|
-
const navigate = useNavigate()
|
|
36
|
-
const { i18n } = useTranslation()
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
history,
|
|
40
|
-
auth,
|
|
41
|
-
setAuth,
|
|
42
|
-
push,
|
|
43
|
-
cleanAll,
|
|
44
|
-
messages,
|
|
45
|
-
setMessages,
|
|
46
|
-
technologies,
|
|
47
|
-
mode,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const [
|
|
66
|
-
const [
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
user,
|
|
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
|
-
let
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
res.parsed.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
handleSubmit={handleSubmit}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
1
|
+
import React, { useState, useEffect } from "react"
|
|
2
|
+
import { useShallow } from "zustand/react/shallow"
|
|
3
|
+
import useStore from "../../utils/store"
|
|
4
|
+
import { publicInteractiveCreation } from "../../utils/rigo"
|
|
5
|
+
import {
|
|
6
|
+
parseLesson,
|
|
7
|
+
// useConsumableCall,
|
|
8
|
+
validateTokens,
|
|
9
|
+
checkParams,
|
|
10
|
+
loginWithToken,
|
|
11
|
+
createCourse,
|
|
12
|
+
isSlugAvailable,
|
|
13
|
+
// reWriteTitle,
|
|
14
|
+
useConsumableCall,
|
|
15
|
+
isValidRigoToken,
|
|
16
|
+
isValidPublicToken,
|
|
17
|
+
} from "../../utils/lib"
|
|
18
|
+
|
|
19
|
+
import Loader from "../Loader"
|
|
20
|
+
import { TMessage } from "../Message"
|
|
21
|
+
import { Lesson } from "../LessonItem"
|
|
22
|
+
import { ConsumablesManager } from "../ConsumablesManager"
|
|
23
|
+
import toast from "react-hot-toast"
|
|
24
|
+
import { ContentIndex } from "./ContentIndex"
|
|
25
|
+
import { Sidebar } from "./Sidebar"
|
|
26
|
+
import Login from "../Login"
|
|
27
|
+
import { useNavigate } from "react-router"
|
|
28
|
+
import { ParamsChecker } from "../ParamsChecker"
|
|
29
|
+
import { randomUUID } from "../../utils/creatorUtils"
|
|
30
|
+
import { RIGO_FLOAT_GIF } from "../../utils/constants"
|
|
31
|
+
import { useTranslation } from "react-i18next"
|
|
32
|
+
import NotificationListener from "../NotificationListener"
|
|
33
|
+
|
|
34
|
+
const SyllabusEditor: React.FC = () => {
|
|
35
|
+
const navigate = useNavigate()
|
|
36
|
+
const { i18n } = useTranslation()
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
history,
|
|
40
|
+
auth,
|
|
41
|
+
setAuth,
|
|
42
|
+
push,
|
|
43
|
+
cleanAll,
|
|
44
|
+
messages,
|
|
45
|
+
setMessages,
|
|
46
|
+
technologies,
|
|
47
|
+
mode,
|
|
48
|
+
uploadedFiles,
|
|
49
|
+
} = useStore(
|
|
50
|
+
useShallow((state) => ({
|
|
51
|
+
history: state.history,
|
|
52
|
+
auth: state.auth,
|
|
53
|
+
setAuth: state.setAuth,
|
|
54
|
+
push: state.push,
|
|
55
|
+
cleanAll: state.cleanAll,
|
|
56
|
+
messages: state.messages,
|
|
57
|
+
// formState: state.formState,
|
|
58
|
+
setMessages: state.setMessages,
|
|
59
|
+
technologies: state.technologies,
|
|
60
|
+
mode: state.mode,
|
|
61
|
+
uploadedFiles: state.uploadedFiles,
|
|
62
|
+
}))
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const [isGenerating, setIsGenerating] = useState(false)
|
|
66
|
+
const [showLoginModal, setShowLoginModal] = useState(false)
|
|
67
|
+
const [isThinking, setIsThinking] = useState(false)
|
|
68
|
+
const [notificationId, setNotificationId] = useState<string>("")
|
|
69
|
+
|
|
70
|
+
const syllabus = history[history.length - 1]
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!syllabus) {
|
|
74
|
+
navigate("/creator", { replace: true })
|
|
75
|
+
}
|
|
76
|
+
}, [syllabus, navigate])
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
;(async () => {
|
|
80
|
+
const { token } = checkParams(["token"])
|
|
81
|
+
if (token) {
|
|
82
|
+
const user = await loginWithToken(token)
|
|
83
|
+
if (user) {
|
|
84
|
+
setAuth({
|
|
85
|
+
bcToken: token,
|
|
86
|
+
userId: user.id,
|
|
87
|
+
rigoToken: user.rigobot.key,
|
|
88
|
+
user,
|
|
89
|
+
publicToken: "",
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})()
|
|
94
|
+
checkSlug()
|
|
95
|
+
}, [])
|
|
96
|
+
|
|
97
|
+
const checkSlug = async () => {
|
|
98
|
+
if (!syllabus.courseInfo.title) {
|
|
99
|
+
toast.error("Please provide a title for the course")
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let newSlug = syllabus.courseInfo.slug
|
|
104
|
+
let isAvailable = await isSlugAvailable(syllabus.courseInfo.slug)
|
|
105
|
+
|
|
106
|
+
while (!isAvailable) {
|
|
107
|
+
if (newSlug.length > 50) {
|
|
108
|
+
newSlug = newSlug.slice(0, 44)
|
|
109
|
+
}
|
|
110
|
+
newSlug = newSlug + "-" + randomUUID()
|
|
111
|
+
newSlug = newSlug.slice(0, 50)
|
|
112
|
+
isAvailable = await isSlugAvailable(newSlug)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
push({
|
|
116
|
+
...syllabus,
|
|
117
|
+
courseInfo: {
|
|
118
|
+
...syllabus.courseInfo,
|
|
119
|
+
slug: newSlug,
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const sendPrompt = async (prompt: string) => {
|
|
125
|
+
setIsThinking(true)
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
let isAuthenticated = false
|
|
129
|
+
let tokenType = ""
|
|
130
|
+
let tokenToUse = ""
|
|
131
|
+
if (auth.rigoToken) {
|
|
132
|
+
const isRigoTokenValid = await isValidRigoToken(auth.rigoToken)
|
|
133
|
+
if (isRigoTokenValid) {
|
|
134
|
+
isAuthenticated = true
|
|
135
|
+
tokenType = "rigo"
|
|
136
|
+
tokenToUse = auth.rigoToken
|
|
137
|
+
} else {
|
|
138
|
+
setAuth({
|
|
139
|
+
...auth,
|
|
140
|
+
rigoToken: "",
|
|
141
|
+
bcToken: "",
|
|
142
|
+
userId: "",
|
|
143
|
+
user: null,
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (auth.publicToken && !isAuthenticated) {
|
|
149
|
+
const isPublicTokenValid = await isValidPublicToken(auth.publicToken)
|
|
150
|
+
if (isPublicTokenValid) {
|
|
151
|
+
isAuthenticated = true
|
|
152
|
+
tokenType = "public"
|
|
153
|
+
tokenToUse = auth.publicToken
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!isAuthenticated) {
|
|
158
|
+
setShowLoginModal(true)
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setMessages([
|
|
163
|
+
...messages,
|
|
164
|
+
{ type: "user", content: prompt },
|
|
165
|
+
{ type: "assistant", content: "" },
|
|
166
|
+
])
|
|
167
|
+
|
|
168
|
+
const lessonsText = JSON.stringify(syllabus.lessons)
|
|
169
|
+
|
|
170
|
+
const res = await publicInteractiveCreation(
|
|
171
|
+
{
|
|
172
|
+
courseInfo:
|
|
173
|
+
JSON.stringify(syllabus.courseInfo) +
|
|
174
|
+
`\nThe following technologies are available, choose up to 3 from the following list: <techs>${technologies
|
|
175
|
+
.filter((t) => t.lang === syllabus.courseInfo.language)
|
|
176
|
+
.map((t) => t.slug)
|
|
177
|
+
.join(", ")}</techs> \nThe following lessons are already in the syllabus: ${lessonsText}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
The following files have been uploaded by the user: ${uploadedFiles.map((f) => `<FILE name="${f.name}">${f.text}</FILE>`).join("\n")}
|
|
181
|
+
You must NEVER delete lessons that are marked as locked.
|
|
182
|
+
`,
|
|
183
|
+
prevInteractions:
|
|
184
|
+
messages
|
|
185
|
+
.map((message) => `${message.type}: ${message.content}`)
|
|
186
|
+
.join("\n") + `\nUSER: ${prompt}`,
|
|
187
|
+
},
|
|
188
|
+
tokenToUse,
|
|
189
|
+
syllabus?.courseInfo?.purpose || "learnpack-lesson-writer",
|
|
190
|
+
tokenType === "rigo" ? false : true
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
setNotificationId(res.notificationId)
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error(error)
|
|
196
|
+
const newMessages = [...messages]
|
|
197
|
+
newMessages.pop()
|
|
198
|
+
setMessages(newMessages as TMessage[])
|
|
199
|
+
setIsThinking(false)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const handleSubmit = async () => {
|
|
204
|
+
if (!auth.bcToken || !auth.rigoToken) {
|
|
205
|
+
setShowLoginModal(true)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!syllabus.courseInfo.title) {
|
|
210
|
+
toast.error("Please provide a title for the course")
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let tokenToUse = auth.rigoToken
|
|
215
|
+
const onValidRigoToken = (rigotoken: string) => {
|
|
216
|
+
setAuth({
|
|
217
|
+
...auth,
|
|
218
|
+
rigoToken: rigotoken,
|
|
219
|
+
})
|
|
220
|
+
tokenToUse = rigotoken
|
|
221
|
+
}
|
|
222
|
+
const isValid = await validateTokens(auth.bcToken, onValidRigoToken)
|
|
223
|
+
if (!isValid) {
|
|
224
|
+
setShowLoginModal(true)
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
const success = await useConsumableCall(
|
|
228
|
+
auth.bcToken,
|
|
229
|
+
"ai-course-generation"
|
|
230
|
+
)
|
|
231
|
+
if (!success) {
|
|
232
|
+
toast.error(
|
|
233
|
+
"You don't have enough credits to generate a course! Please add more credits to your account."
|
|
234
|
+
)
|
|
235
|
+
toast.loading("You will be redirected to the settings page in 5 seconds.")
|
|
236
|
+
setTimeout(() => {
|
|
237
|
+
window.location.href =
|
|
238
|
+
"https://learnpack.co/settings?token=" + auth.bcToken
|
|
239
|
+
}, 5000)
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
setIsGenerating(true)
|
|
244
|
+
|
|
245
|
+
const timeout = setTimeout(() => {
|
|
246
|
+
cleanAll()
|
|
247
|
+
window.location.href = `/preview/${syllabus.courseInfo.slug}?token=${auth.bcToken}&language=${syllabus.courseInfo.language}&mode=${mode}`
|
|
248
|
+
}, 8000)
|
|
249
|
+
try {
|
|
250
|
+
await createCourse(syllabus, tokenToUse, auth.bcToken)
|
|
251
|
+
} catch (error) {
|
|
252
|
+
console.error("Failed to create course:", error)
|
|
253
|
+
clearTimeout(timeout)
|
|
254
|
+
setIsGenerating(false)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (!syllabus) return null
|
|
259
|
+
|
|
260
|
+
console.log(syllabus.courseInfo)
|
|
261
|
+
|
|
262
|
+
return isGenerating ? (
|
|
263
|
+
<>
|
|
264
|
+
<Loader
|
|
265
|
+
listeningTo="course-generation"
|
|
266
|
+
icon={<img src={RIGO_FLOAT_GIF} alt="rigo" className="w-20 h-20" />}
|
|
267
|
+
initialBuffer="🚀 Starting course generation..."
|
|
268
|
+
text="Learnpack is setting up your tutorial.
|
|
269
|
+
It may take a moment..."
|
|
270
|
+
/>
|
|
271
|
+
</>
|
|
272
|
+
) : (
|
|
273
|
+
<div className="flex w-full bg-white rounded-md shadow-md overflow-hidden h-screen ">
|
|
274
|
+
<ParamsChecker />
|
|
275
|
+
<NotificationListener
|
|
276
|
+
onNotification={(res) => {
|
|
277
|
+
const lessons: Lesson[] = res.parsed.listOfSteps.map((step: any) =>
|
|
278
|
+
parseLesson(step, syllabus.lessons)
|
|
279
|
+
)
|
|
280
|
+
push({
|
|
281
|
+
...syllabus,
|
|
282
|
+
lessons: lessons,
|
|
283
|
+
courseInfo: {
|
|
284
|
+
...syllabus.courseInfo,
|
|
285
|
+
title: res.parsed.title || syllabus.courseInfo.title,
|
|
286
|
+
description:
|
|
287
|
+
res.parsed.description || syllabus.courseInfo.description,
|
|
288
|
+
language:
|
|
289
|
+
res.parsed.languageCode || syllabus.courseInfo.language || "en",
|
|
290
|
+
technologies:
|
|
291
|
+
res.parsed.technologies.length > 0
|
|
292
|
+
? res.parsed.technologies
|
|
293
|
+
: syllabus.courseInfo.technologies || [],
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
if (res.parsed.languageCode) {
|
|
298
|
+
i18n.changeLanguage(res.parsed.languageCode)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
setMessages((prev) => [
|
|
302
|
+
...prev.filter((m) => Boolean(m.content)),
|
|
303
|
+
{
|
|
304
|
+
type: "assistant",
|
|
305
|
+
content: res.parsed.aiMessage,
|
|
306
|
+
},
|
|
307
|
+
])
|
|
308
|
+
setIsThinking(false)
|
|
309
|
+
setNotificationId("")
|
|
310
|
+
}}
|
|
311
|
+
notificationId={notificationId}
|
|
312
|
+
/>
|
|
313
|
+
{showLoginModal && (
|
|
314
|
+
<Login
|
|
315
|
+
onFinish={() => {
|
|
316
|
+
setShowLoginModal(false)
|
|
317
|
+
}}
|
|
318
|
+
/>
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
<ConsumablesManager />
|
|
322
|
+
|
|
323
|
+
<Sidebar
|
|
324
|
+
// messages={messages}
|
|
325
|
+
sendPrompt={sendPrompt}
|
|
326
|
+
handleSubmit={handleSubmit}
|
|
327
|
+
/>
|
|
328
|
+
|
|
329
|
+
<ContentIndex
|
|
330
|
+
handleSubmit={handleSubmit}
|
|
331
|
+
messages={messages}
|
|
332
|
+
isThinking={isThinking}
|
|
333
|
+
openLogin={() => {
|
|
334
|
+
setShowLoginModal(true)
|
|
335
|
+
}}
|
|
336
|
+
/>
|
|
337
|
+
</div>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export default SyllabusEditor
|