
{
const store = configureStore({
@@ -15,6 +17,8 @@ const makeStore = (/* preloadedState */) => {
lessonPageEditor: lessonPageEditorSlice.reducer,
teamSlice: teamSlice.reducer,
[lessonsApi.reducerPath]: lessonsApi.reducer,
+ [lessonsSlice.reducerPath]: lessonsSlice.reducer,
+ [lessonPageSlice.reducerPath]: lessonPageSlice.reducer,
[organizationApi.reducerPath]: organizationApi.reducer,
[teamSlice.reducerPath]: teamSlice.reducer,
},
diff --git a/src/core/utils/webSocket.ts b/src/core/utils/webSocket.ts
index 6ef2078..9a33933 100644
--- a/src/core/utils/webSocket.ts
+++ b/src/core/utils/webSocket.ts
@@ -10,6 +10,15 @@ enum WebSocketReceivedMessagesCmds {
TeamAddedMember = 5,
TeamUpdatedMemberRole = 6,
TeamDeletedMember = 7,
+ LessonCreated = 8,
+ LessonPreviewTitleUpdated = 9,
+ LessonPreviewThumbnailUpdated = 10,
+ LessonStateUpdated = 11,
+ LessonAddedContent = 12,
+ LessonDeletedContent = 13,
+ LessonContentUpdated = 14,
+ LessonContentUpdatedPosition = 15,
+ LessonContentFileUpdated = 16,
}
export { WebSocketSendMessagesCmds, WebSocketReceivedMessagesCmds };
diff --git a/src/features/Lessons/LessonPage/index.tsx b/src/features/Lessons/LessonPage/index.tsx
index b519540..d0e1b66 100644
--- a/src/features/Lessons/LessonPage/index.tsx
+++ b/src/features/Lessons/LessonPage/index.tsx
@@ -1,63 +1,96 @@
-import { Button, Flex } from 'antd';
-import { CheckOutlined } from '@ant-design/icons';
-import HeaderBar from '../../../core/components/Header';
-import { useLocation, useNavigate, useParams } from 'react-router-dom';
-import { Constants } from '../../../core/utils/utils';
-import React from 'react';
-import MySpin from 'shared/components/MySpin';
-import MyErrorResult from 'shared/components/MyResult';
-import MyEmpty from 'shared/components/MyEmpty';
-import { useGetLessonContentsQuery } from 'core/services/lessons';
-import MyMiddleCard from 'shared/components/MyMiddleCard';
-import { Converter } from '../converter';
-import Questions from '../Questions';
+import { Button, Flex } from "antd";
+import { CheckOutlined } from "@ant-design/icons";
+import HeaderBar from "core/components/Header";
+import { useLocation, useNavigate, useParams } from "react-router-dom";
+import { Constants } from "core/utils/utils";
+import React, { useEffect } from "react";
+import MyErrorResult from "shared/components/MyResult";
+import MyEmpty from "shared/components/MyEmpty";
+import { useGetLessonContentsQuery } from "core/services/lessons";
+import MyMiddleCard from "shared/components/MyMiddleCard";
+import { Converter } from "../converter";
+import Questions from "../Questions";
+import {
+ addWebSocketReconnectListener,
+ removeWebSocketReconnectListener,
+} from "core/services/websocketService";
+import { useDispatch, useSelector } from "react-redux";
+import {
+ lessonPageContents,
+ setLessonPageContents,
+ setLessonPageCurrentLessonId,
+} from "./lessonPageSlice";
+import MyCenteredSpin from "shared/components/MyCenteredSpin";
const LessonContents: React.FC = () => {
- const { lessonId } = useParams();
+ const dispatch = useDispatch();
+ const { lessonId } = useParams();
- const { data, error, isLoading } = useGetLessonContentsQuery(lessonId as string, {
- refetchOnMountOrArgChange: true,
- });
+ const lessonContents = useSelector(lessonPageContents);
- if (isLoading) return
;
- if (error) return
;
+ const { data, error, isLoading, refetch } = useGetLessonContentsQuery(
+ lessonId as string,
+ {
+ refetchOnMountOrArgChange: true,
+ }
+ );
- if (!data || data.length === 0) return
;
+ useEffect(() => {
+ dispatch(setLessonPageCurrentLessonId(lessonId as string));
+ addWebSocketReconnectListener(refetch);
- return (
- <>
- {data.map((lessonContent) => (
-
-
-
- ))}
- >
- );
+ return () => removeWebSocketReconnectListener(refetch);
+ }, []);
+
+ useEffect(() => {
+ if (!data) return;
+
+ dispatch(setLessonPageContents(data));
+ }, [data]);
+
+ if (isLoading) return
;
+ if (error) return
;
+
+ if (!lessonContents || lessonContents.length === 0) return
;
+
+ return (
+ <>
+ {lessonContents.map((lessonContent) => (
+
+
+
+ ))}
+ >
+ );
};
export default function LessonPage() {
- const location = useLocation();
- const navigate = useNavigate();
+ const location = useLocation();
+ const navigate = useNavigate();
- return (
- <>
-
navigate(`${location.pathname}/editor`)} />
+ return (
+ <>
+ navigate(`${location.pathname}/editor`)}
+ />
-
-
-
- }
- >
-