diff --git a/src/components/CollectionEditor.tsx b/src/components/CollectionEditor.tsx index d657565..961b08f 100644 --- a/src/components/CollectionEditor.tsx +++ b/src/components/CollectionEditor.tsx @@ -13,8 +13,8 @@ import { } from "@/services/LocalStorageService"; const CollectionEditor: React.FC = () => { const router = useRouter(); - const { identifier, mode } = router.query; - + const { identifier } = router.query; + const [mode, setMode] = useState(); const [fullName, setFullName] = useState("Anonymous User"); const [userId, setUserId] = useState(TENANT_ID); const [deviceId, setDeviceId] = useState(""); @@ -24,6 +24,8 @@ const CollectionEditor: React.FC = () => { useEffect(() => { const storedFullName = getLocalStoredUserName(); const storedUserId = getLocalStoredUserId() || TENANT_ID; + const storedMode = localStorage.getItem("contentMode"); + setMode(storedMode || "edit"); setFullName(storedFullName ?? "Anonymous User"); setUserId(storedUserId); diff --git a/src/components/KaTableComponent.tsx b/src/components/KaTableComponent.tsx index c87ad61..5e91c44 100644 --- a/src/components/KaTableComponent.tsx +++ b/src/components/KaTableComponent.tsx @@ -1,15 +1,15 @@ -import React, { useState } from 'react'; -import { Table as KaTable } from 'ka-table'; -import { DataType, EditingMode, SortingMode } from 'ka-table/enums'; -import { Typography, useTheme, IconButton, Box, Grid } from '@mui/material'; -import UpReviewTinyImage from '@mui/icons-material/LibraryBooks'; +import React, { useState } from "react"; +import { Table as KaTable } from "ka-table"; +import { DataType, EditingMode, SortingMode } from "ka-table/enums"; +import { Typography, useTheme, IconButton, Box, Grid } from "@mui/material"; +import UpReviewTinyImage from "@mui/icons-material/LibraryBooks"; import "ka-table/style.css"; import DeleteIcon from "@mui/icons-material/Delete"; import router from "next/router"; import { MIME_TYPE } from "@/utils/app.config"; import Image from "next/image"; -import ActionIcon from './ActionIcon'; -import { Padding } from '@mui/icons-material'; +import ActionIcon from "./ActionIcon"; +import { Padding } from "@mui/icons-material"; interface CustomTableProps { data: any[]; // Define a more specific type for your data if needed columns: Array<{ @@ -18,16 +18,19 @@ interface CustomTableProps { dataType: DataType; }>; handleDelete?: any; - tableTitle?: string + tableTitle?: string; } -const KaTableComponent: React.FC = ({ data, columns, tableTitle }) => { +const KaTableComponent: React.FC = ({ + data, + columns, + tableTitle, +}) => { const theme = useTheme(); const [open, setOpen] = useState(false); - - console.log(data) - console.log(columns) + console.log(data); + console.log(columns); const handleClose = () => { setOpen(false); @@ -35,17 +38,18 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl const handleOpen = () => setOpen(true); const openEditor = (content: any) => { - console.log("content", content) + console.log("content", content); const identifier = content?.identifier; let mode = content?.mode; // default mode from content, can be overwritten by tableTitle + switch (tableTitle) { - case 'draft': + case "draft": mode = !mode ? "edit" : mode; - + localStorage.setItem("contentMode", mode); // Use draft-specific routing if (content?.mimeType === MIME_TYPE.QUESTIONSET_MIME_TYPE) { - router.push({ pathname: `/editor`, query: { identifier, mode } }); + router.push({ pathname: `/editor`, query: { identifier } }); } else if ( content?.mimeType && MIME_TYPE.GENERIC_MIME_TYPE.includes(content?.mimeType) @@ -56,72 +60,111 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl content?.mimeType && MIME_TYPE.COLLECTION_MIME_TYPE.includes(content?.mimeType) ) { - router.push({ pathname: `/collection`, query: { identifier, mode } }); + router.push({ pathname: `/collection`, query: { identifier } }); } return; // Exit early since draft has specific routing logic - case 'publish': - mode = "read"; - break; - case 'discover-contents': - mode = "read"; - break; - case 'submitted': + case "publish": + case "discover-contents": + case "submitted": mode = "read"; break; - case 'upForReview': + + case "upForReview": mode = "review"; break; - case 'all-content': - mode = content?.status === "Draft" || content?.status === "Live" ? "edit" : "review" + + case "all-content": + mode = + content?.status === "Draft" || content?.status === "Live" + ? "edit" + : "review"; break; - // Default case for "all-content" or any other values if mode is already defined in content + default: mode = mode || "read"; break; } - // Generic routing for cases other than 'draft' + // Save mode in localStorage + localStorage.setItem("contentMode", mode); + // Generic routing for cases other than 'draft' if (content?.mimeType === MIME_TYPE.QUESTIONSET_MIME_TYPE) { - router.push({ pathname: `/editor`, query: { identifier, mode } }); - } - else if (tableTitle === 'submitted') { - content.contentType === "Course" ? router.push({ pathname: `/course-hierarchy/${identifier}`, query: { identifier, mode } }) : - router.push({ pathname: `/workspace/content/review`, query: { identifier, mode } }); - } - else if (tableTitle === 'all-content' && mode === "review") { - content.contentType === "Course" ? router.push({ pathname: `/course-hierarchy/${identifier}`, query: { identifier, mode, isReadOnly: true } }) : - router.push({ pathname: `/workspace/content/review`, query: { identifier, mode, isReadOnly: true } }); - } - else if (tableTitle === 'discover-contents') { - content.contentType === "Course" ? router.push({ pathname: `/course-hierarchy/${identifier}`, query: { identifier, mode, isDiscoverContent: true } }) : - router.push({ pathname: `/workspace/content/review`, query: { identifier, mode, isDiscoverContent: true } }); - } - else if (content?.mimeType && MIME_TYPE.GENERIC_MIME_TYPE.includes(content?.mimeType)) { - localStorage.setItem('contentCreatedBy', content?.createdBy); - console.log(content) - const pathname = tableTitle === 'upForReview' ? `/workspace/content/review` : `/upload-editor`; - // content.contentType === "Course" ? router.push({ pathname:`/course-hierarchy/${identifier}`, query: { identifier, mode } }) : - router.push({ pathname, query: { identifier, mode } }); - } else if (content?.mimeType && MIME_TYPE.COLLECTION_MIME_TYPE.includes(content?.mimeType)) { - router.push({ pathname: `/collection`, query: { identifier, mode } }); + router.push({ pathname: `/editor`, query: { identifier } }); + } else if (tableTitle === "submitted") { + content.contentType === "Course" + ? router.push({ + pathname: `/course-hierarchy/${identifier}`, + query: { identifier }, + }) + : router.push({ + pathname: `/workspace/content/review`, + query: { identifier }, + }); + } else if (tableTitle === "all-content" && mode === "review") { + content.contentType === "Course" + ? router.push({ + pathname: `/course-hierarchy/${identifier}`, + query: { identifier, isReadOnly: true }, + }) + : router.push({ + pathname: `/workspace/content/review`, + query: { identifier, isReadOnly: true }, + }); + } else if (tableTitle === "discover-contents") { + content.contentType === "Course" + ? router.push({ + pathname: `/course-hierarchy/${identifier}`, + query: { identifier, isDiscoverContent: true }, + }) + : router.push({ + pathname: `/workspace/content/review`, + query: { identifier, isDiscoverContent: true }, + }); + } else if ( + content?.mimeType && + MIME_TYPE.GENERIC_MIME_TYPE.includes(content?.mimeType) + ) { + localStorage.setItem("contentCreatedBy", content?.createdBy); + console.log(content); + const pathname = + tableTitle === "upForReview" + ? `/workspace/content/review` + : `/upload-editor`; + router.push({ pathname, query: { identifier } }); + } else if ( + content?.mimeType && + MIME_TYPE.COLLECTION_MIME_TYPE.includes(content?.mimeType) + ) { + router.push({ pathname: `/collection`, query: { identifier } }); } }; + return ( <> { - if (props.column.key === 'name' || props.column.key === "title_and_description") { + if ( + props.column.key === "name" || + props.column.key === "title_and_description" + ) { return ( -
openEditor(props.rowData)} > +
openEditor(props.rowData)} + > {props.rowData.image ? ( @@ -136,7 +179,7 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl }} > Image = ({ data, columns, tableTitl }} /> - ) : props.column.key === 'name' ? ( + ) : props.column.key === "name" ? ( = ({ data, columns, tableTitl }} > Image = ({ data, columns, tableTitl objectFit: "cover", borderRadius: "8px", }} - /> ) : ( @@ -184,7 +226,7 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl }} > Image = ({ data, columns, tableTitl objectFit: "cover", borderRadius: "8px", }} - /> )} @@ -201,110 +242,132 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl
- {props.rowData.name} + + {props.rowData.name} +
- - {props.column.key === 'name' ? props.rowData.primaryCategory : props.rowData.description} + + {props.column.key === "name" + ? props.rowData.primaryCategory + : props.rowData.description}
- -
); - } - else if (props.column.key === "status") { + } else if (props.column.key === "status") { if (props.rowData.status === "Draft") { return ( - + {props.rowData.status} - ) + ); } if (props.rowData.status === "Review") { return ( - + {props.rowData.status} - ) + ); } if (props.rowData.status === "Live") { return ( - + {props.rowData.status} - ) + ); } - } - - else if (props.column.key === "create-by") { - console.log('props.rowData ====>', props.rowData) + } else if (props.column.key === "create-by") { + console.log("props.rowData ====>", props.rowData); if (props?.rowData?.creator || props?.rowData?.author) return ( - + {props?.rowData?.creator || props?.rowData?.author} - ) + ); else return ( - + - - ) - - } - else if (props.column.key === 'contentAction') { + ); + } else if (props.column.key === "contentAction") { { return ( <> - - - - - + + ); } - } - else if (props.column.key === 'action') { - - + } else if (props.column.key === "action") { return ( - - - - + + ); - } - - - else if (props.column.key === "contentType") { + } else if (props.column.key === "contentType") { return ( - + {props?.rowData?.contentType} - ); - } else if (props.column.key === "lastUpdatedOn") { return ( - + {props?.rowData?.lastUpdatedOn} - ); - } return props.children; @@ -316,7 +379,6 @@ const KaTableComponent: React.FC = ({ data, columns, tableTitl }} /> - ); }; diff --git a/src/components/QuestionSetEditor.tsx b/src/components/QuestionSetEditor.tsx index 0b63c18..e9a8a63 100644 --- a/src/components/QuestionSetEditor.tsx +++ b/src/components/QuestionSetEditor.tsx @@ -1,12 +1,20 @@ import React, { useEffect, useRef, useState } from "react"; import { useRouter } from "next/router"; import { v4 as uuidv4 } from "uuid"; -import { TENANT_ID, CHANNEL_ID, FRAMEWORK_ID, CLOUD_STORAGE_URL } from "@/utils/app.config"; -import { getLocalStoredUserId, getLocalStoredUserName } from "@/services/LocalStorageService"; +import { + TENANT_ID, + CHANNEL_ID, + FRAMEWORK_ID, + CLOUD_STORAGE_URL, +} from "@/utils/app.config"; +import { + getLocalStoredUserId, + getLocalStoredUserName, +} from "@/services/LocalStorageService"; const QuestionSetEditor: React.FC = () => { const router = useRouter(); - const { identifier, mode } = router.query; - + const { identifier } = router.query; + const [mode, setMode] = useState(); const [fullName, setFullName] = useState("Anonymous User"); const [userId, setUserId] = useState(TENANT_ID); const [deviceId, setDeviceId] = useState("7e85b4967aebd6704ba1f604f20056b6"); @@ -16,6 +24,8 @@ const QuestionSetEditor: React.FC = () => { useEffect(() => { const storedFullName = getLocalStoredUserName(); const storedUserId = getLocalStoredUserId() || TENANT_ID; + const storedMode = localStorage.getItem("contentMode"); + setMode(storedMode || "edit"); setFullName(storedFullName ?? "Anonymous User"); setUserId(storedUserId); @@ -50,7 +60,7 @@ const QuestionSetEditor: React.FC = () => { { id: CHANNEL_ID, type: "pratham-portal", - } + }, ], timeDiff: 5, objectRollup: {}, @@ -68,7 +78,7 @@ const QuestionSetEditor: React.FC = () => { cloudStorage: { provider: "aws", presigned_headers: {}, - } + }, }, config: { mode: mode || "edit", @@ -181,8 +191,12 @@ const QuestionSetEditor: React.FC = () => { "editorEmitter", (event: any) => { console.log("Editor event:", event); - if (event.detail?.action === "backContent" || event.detail?.action === "submitContent" || - event.detail?.action === "publishContent" || event.detail?.action === "rejectContent") { + if ( + event.detail?.action === "backContent" || + event.detail?.action === "submitContent" || + event.detail?.action === "publishContent" || + event.detail?.action === "rejectContent" + ) { window.history.back(); window.addEventListener( "popstate",