Добавлены новые функции генерации уроков с использованием ИИ в компонент LessonList и соответствующие изменения в форме создания урока. Обновлены локализации для поддержки новых функций. Реализован API для генерации уроков и добавлены тестовые данные для имитации ответов сервера.
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
Tr,
|
||||
Th,
|
||||
Tbody,
|
||||
Td,
|
||||
Text,
|
||||
AlertDialog,
|
||||
AlertDialogBody,
|
||||
@@ -48,6 +49,13 @@ const LessonList = () => {
|
||||
const { courseId } = useParams()
|
||||
const user = useAppSelector((s) => s.user)
|
||||
const { data, isLoading, error, isSuccess } = api.useLessonListQuery(courseId)
|
||||
const [generateLessonsMutation, {
|
||||
data: generateLessons,
|
||||
isLoading: isLoadingGenerateLessons,
|
||||
error: errorGenerateLessons,
|
||||
isSuccess: isSuccessGenerateLessons
|
||||
}, ] = api.useGenerateLessonsMutation()
|
||||
|
||||
const [createLesson, crLQuery] = api.useCreateLessonMutation()
|
||||
const [deleteLesson, deletingRqst] = api.useDeleteLessonMutation()
|
||||
const [updateLesson, updateLessonRqst] = api.useUpdateLessonMutation()
|
||||
@@ -58,6 +66,7 @@ const LessonList = () => {
|
||||
const toastRef = useRef(null)
|
||||
const createdLessonRef = useRef(null)
|
||||
const [editLesson, setEditLesson] = useState<Lesson>(null)
|
||||
const [suggestedLessonToCreate, setSuggestedLessonToCreate] = useState(null)
|
||||
const { t } = useTranslation()
|
||||
const sorted = useMemo(
|
||||
() => [...(data?.body || [])]?.sort((a, b) => (a.date > b.date ? 1 : -1)),
|
||||
@@ -93,6 +102,18 @@ const LessonList = () => {
|
||||
return lessonsData.sort((a, b) => (a.date < b.date ? 1 : -1))
|
||||
}, [groupByDate, isSuccess, sorted])
|
||||
|
||||
useEffect(() => {
|
||||
if (isTeacher(user) && !isSuccessGenerateLessons) {
|
||||
generateLessonsMutation(courseId)
|
||||
}
|
||||
}, [isSuccessGenerateLessons, user, courseId, generateLessonsMutation])
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccessGenerateLessons) {
|
||||
console.log(generateLessons)
|
||||
}
|
||||
}, [isSuccessGenerateLessons])
|
||||
|
||||
const onSubmit = (lessonData) => {
|
||||
toastRef.current = toast({
|
||||
title: t('journal.pl.common.sending'),
|
||||
@@ -174,6 +195,18 @@ const LessonList = () => {
|
||||
}
|
||||
}, [updateLessonRqst.isSuccess])
|
||||
|
||||
// Обработчик выбора предложения ИИ в форме
|
||||
const handleSelectAiSuggestion = (suggestion) => {
|
||||
setSuggestedLessonToCreate(suggestion)
|
||||
}
|
||||
|
||||
// Очищаем выбранную сгенерированную лекцию при закрытии формы
|
||||
const handleCancelForm = () => {
|
||||
setShowForm(false)
|
||||
setEditLesson(null)
|
||||
setSuggestedLessonToCreate(null)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <XlSpinner />
|
||||
}
|
||||
@@ -234,17 +267,18 @@ const LessonList = () => {
|
||||
<Box mt="15" mb="15">
|
||||
{showForm ? (
|
||||
<LessonForm
|
||||
key={editLesson?.id}
|
||||
key={editLesson?.id || 'new-lesson'}
|
||||
isLoading={crLQuery.isLoading}
|
||||
onSubmit={onSubmit}
|
||||
onCancel={() => {
|
||||
setShowForm(false)
|
||||
setEditLesson(null)
|
||||
}}
|
||||
onCancel={handleCancelForm}
|
||||
error={(crLQuery.error as any)?.error}
|
||||
lesson={editLesson}
|
||||
lesson={editLesson || suggestedLessonToCreate || undefined}
|
||||
title={editLesson ? t('journal.pl.lesson.editTitle') : t('journal.pl.lesson.createTitle')}
|
||||
nameButton={editLesson ? t('journal.pl.edit') : t('journal.pl.common.create')}
|
||||
aiSuggestions={generateLessons?.body || []}
|
||||
isLoadingAiSuggestions={isLoadingGenerateLessons}
|
||||
onSelectAiSuggestion={handleSelectAiSuggestion}
|
||||
selectedAiSuggestion={suggestedLessonToCreate}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user