diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index 9a0dabd..abf0d75 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -66,6 +66,7 @@ const CourseCard: React.FC = ({ return ( = ({ width: "250px", }} > - + = ({ <>
- {loadingText}... + {loadingText}... ); }; diff --git a/src/pages/workspace/content/allContents/index.tsx b/src/pages/workspace/content/allContents/index.tsx index 92b17ae..dd87eaf 100644 --- a/src/pages/workspace/content/allContents/index.tsx +++ b/src/pages/workspace/content/allContents/index.tsx @@ -15,10 +15,12 @@ import { import DeleteIcon from "@mui/icons-material/Delete"; import UpReviewTinyImage from "@mui/icons-material/LibraryBooks"; import SearchBox from "../../../../components/SearchBox"; -import { getContent } from "../../../../services/ContentService"; +import { deleteContent, getContent } from "../../../../services/ContentService"; import { timeAgo } from "@/utils/Helper"; import Loader from "@/components/Loader"; import NoDataFound from "@/components/NoDataFound"; +import { MIME_TYPE } from "@/utils/app.config"; +import router from "next/router"; const AllContentsPage = () => { const theme = useTheme(); @@ -31,6 +33,7 @@ const AllContentsPage = () => { const [sortBy, setSortBy] = useState("updated"); const [contentList, setContentList] = React.useState([]); const [loading, setLoading] = useState(false); + const [contentDeleted, setContentDeleted] = React.useState(false); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); @@ -67,6 +70,19 @@ const AllContentsPage = () => { setSortBy(sortBy); }; + const openEditor = (content: any) => { + const identifier = content?.identifier; + const mode = content?.mode; + if (content?.mimeType === MIME_TYPE.QUESTIONSET_MIME_TYPE) { + router.push({ pathname: `/editor`, query: { identifier, mode } }); + } else if ( + content?.mimeType && + MIME_TYPE.GENERIC_MIME_TYPE.includes(content?.mimeType) + ) { + router.push({ pathname: `/upload-editor`, query: { identifier } }); + } + }; + useEffect(() => { const getContentList = async () => { try { @@ -82,7 +98,9 @@ const AllContentsPage = () => { ]; const query = debouncedSearchTerm || ""; const response = await getContent(status, query); - const contentList = (response?.content || []).concat(response?.QuestionSet || []); + const contentList = (response?.content || []).concat( + response?.QuestionSet || [] + ); setContentList(contentList); setLoading(false); } catch (error) { @@ -90,7 +108,21 @@ const AllContentsPage = () => { } }; getContentList(); - }, [debouncedSearchTerm]); + }, [debouncedSearchTerm, contentDeleted]); + + const handleDeleteClick = async (content: any) => { + if (content?.identifier && content?.mimeType) { + try { + await deleteContent(content?.identifier, content?.mimeType); + console.log(`Deleted item with identifier - ${content?.identifier}`); + setTimeout(() => { + setContentDeleted((prev) => !prev); + }, 1000); + } catch (error) { + console.error("Failed to delete content:", error); + } + } + }; const filteredData = useMemo( () => @@ -132,8 +164,12 @@ const AllContentsPage = () => { {contentList?.map((content, index) => ( - - + openEditor(content)}> + {content?.appIcon ? ( ) : ( @@ -156,7 +192,10 @@ const AllContentsPage = () => { {content?.status} {content?.status === "Draft" && ( - + handleDeleteClick(content)} + > )} diff --git a/src/pages/workspace/content/draft/index.tsx b/src/pages/workspace/content/draft/index.tsx index bcae7e2..fdeeb5f 100644 --- a/src/pages/workspace/content/draft/index.tsx +++ b/src/pages/workspace/content/draft/index.tsx @@ -68,7 +68,9 @@ const DraftPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); - setContentDeleted((prev) => !prev); + setTimeout(() => { + setContentDeleted((prev) => !prev); + }, 1000); }; useEffect(() => { diff --git a/src/pages/workspace/content/publish/index.tsx b/src/pages/workspace/content/publish/index.tsx index 7556fee..6fd23d4 100644 --- a/src/pages/workspace/content/publish/index.tsx +++ b/src/pages/workspace/content/publish/index.tsx @@ -56,7 +56,9 @@ const PublishPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); - setContentDeleted((prev) => !prev); + setTimeout(() => { + setContentDeleted((prev) => !prev); + }, 1000); }; useEffect(() => { diff --git a/src/pages/workspace/content/submitted/index.tsx b/src/pages/workspace/content/submitted/index.tsx index cc6f149..50930b8 100644 --- a/src/pages/workspace/content/submitted/index.tsx +++ b/src/pages/workspace/content/submitted/index.tsx @@ -6,6 +6,7 @@ import SearchBox from "../../../../components/SearchBox"; import { getContent } from "@/services/ContentService"; import Loader from "@/components/Loader"; import NoDataFound from "@/components/NoDataFound"; +import { setTimeout } from "timers"; const SubmittedForReviewPage = () => { const [selectedKey, setSelectedKey] = useState("submitted"); @@ -55,7 +56,9 @@ const SubmittedForReviewPage = () => { const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); - setContentDeleted((prev) => !prev); + setTimeout(() => { + setContentDeleted((prev) => !prev); + }, 1000); }; useEffect(() => {