diff --git a/src/pages/lesson-list.tsx b/src/pages/lesson-list.tsx index 7a0a853..b11061f 100644 --- a/src/pages/lesson-list.tsx +++ b/src/pages/lesson-list.tsx @@ -194,12 +194,13 @@ const LessonList = () => { const toastRef = useRef(null) const createdLessonRef = useRef(null) const [editLesson, setEditLesson] = useState(null) + const sorted = useMemo(() => [...(data?.body || [])]?.sort((a, b) => a.date < b.date ? 1 : -1), [data, data?.body]) + const lessonCalc = useMemo(() => { if (!isSuccess) { return [] } - const sorted = [...data?.body].sort((a, b) => a.date > b.date ? 1 : -1) if (!groupByDate) { return [{ date: '', data: sorted }] @@ -223,7 +224,7 @@ const LessonList = () => { } return lessonsData - }, [groupByDate, isSuccess]) + }, [groupByDate, isSuccess, sorted]) const onSubmit = (lessonData) => { toastRef.current = toast({ @@ -404,10 +405,10 @@ const LessonList = () => { )} )} - {barFeature && ( + {barFeature && sorted?.length && ( ({ + data={sorted.map((lesson, index) => ({ lessonIndex: `#${index + 1}`, count: lesson.students.length, }))}