From 3357c9ddd02bed72cc188e61e839449d1e053ee3 Mon Sep 17 00:00:00 2001 From: primakov Date: Sun, 23 Mar 2025 15:00:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=20LessonList:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D1=83=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=20=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D1=80=D1=8B=D1=82=D0=B8=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=83=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2.=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8B=20Item=20=D0=B8=20LessonItems=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B9=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F.=20=D0=A3=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=89=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D1=83=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/lesson-list/components/item.tsx | 8 ++++- .../lesson-list/components/lesson-items.tsx | 3 ++ src/pages/lesson-list/lesson-list.tsx | 34 +++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/pages/lesson-list/components/item.tsx b/src/pages/lesson-list/components/item.tsx index 01ff631..cb94266 100644 --- a/src/pages/lesson-list/components/item.tsx +++ b/src/pages/lesson-list/components/item.tsx @@ -30,6 +30,7 @@ type ItemProps = { isTeacher: boolean courseId: string setlessonToDelete(): void + setEditLesson?: () => void students: unknown[] } @@ -40,6 +41,7 @@ export const Item: React.FC = ({ isTeacher, courseId, setlessonToDelete, + setEditLesson, students, }) => { const [edit, setEdit] = useState(false) @@ -128,7 +130,11 @@ export const Item: React.FC = ({ { - setEdit(true) + if (setEditLesson) { + setEditLesson(); + } else { + setEdit(true); + } }} > {t('journal.pl.edit')} diff --git a/src/pages/lesson-list/components/lesson-items.tsx b/src/pages/lesson-list/components/lesson-items.tsx index b78decc..e0075bc 100644 --- a/src/pages/lesson-list/components/lesson-items.tsx +++ b/src/pages/lesson-list/components/lesson-items.tsx @@ -15,6 +15,7 @@ type LessonItemProps = { isTeacher: boolean courseId: string setlessonToDelete(lesson: Lesson): void + setEditLesson?(lesson: Lesson): void } export const LessonItems: React.FC = ({ @@ -23,6 +24,7 @@ export const LessonItems: React.FC = ({ isTeacher, courseId, setlessonToDelete, + setEditLesson, }) => ( <> {date && ( @@ -37,6 +39,7 @@ export const LessonItems: React.FC = ({ key={lesson.id} {...lesson} setlessonToDelete={() => setlessonToDelete(lesson)} + setEditLesson={setEditLesson ? () => setEditLesson(lesson) : undefined} courseId={courseId} isTeacher={isTeacher} /> diff --git a/src/pages/lesson-list/lesson-list.tsx b/src/pages/lesson-list/lesson-list.tsx index 2f9bb7d..2c4c205 100644 --- a/src/pages/lesson-list/lesson-list.tsx +++ b/src/pages/lesson-list/lesson-list.tsx @@ -102,12 +102,6 @@ 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) @@ -205,6 +199,31 @@ const LessonList = () => { setShowForm(false) setEditLesson(null) setSuggestedLessonToCreate(null) + + // Сбрасываем флаги генерации, чтобы при повторном открытии формы + // генерация запускалась снова + if (generateLessons) { + // Сбрасываем данные генерации (если в API есть такая возможность) + // или при повторном открытии формы будем перезапрашивать данные + } + } + + // Обработчик открытия формы создания новой лекции + const handleOpenForm = () => { + setShowForm(true) + + // Запускаем генерацию лекций только при открытии формы создания новой лекции + // и если генерация ещё не была запущена + if (isTeacher(user) && !editLesson && !generateLessons && !isLoadingGenerateLessons) { + generateLessonsMutation(courseId) + } + } + + // Обработчик редактирования существующей лекции + const handleEditLesson = (lesson) => { + setEditLesson(lesson) + setShowForm(true) + // Не запускаем генерацию при редактировании } if (isLoading) { @@ -284,7 +303,7 @@ const LessonList = () => { @@ -326,6 +345,7 @@ const LessonList = () => { isTeacher={isTeacher(user)} lessons={lessons} setlessonToDelete={setlessonToDelete} + setEditLesson={handleEditLesson} key={date} /> ))}