diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index 593fb18..5226662 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -16,7 +16,7 @@ import { Status } from "@/utils/app.constant"; interface ContentCardProps { title: string; - description: string; + description?: string; type: string; imageUrl?: string; status: string; @@ -54,11 +54,7 @@ const CourseCard: React.FC = ({ }} > {imageUrl ? ( - {title} + {title} ) : ( )} @@ -75,14 +71,12 @@ const CourseCard: React.FC = ({ }} /> - {title} {description} - {(status === Status.DRAFT || status === Status.LIVE) && ( diff --git a/src/pages/workspace/content/allContents/index.tsx b/src/pages/workspace/content/allContents/index.tsx index c9417a0..0093867 100644 --- a/src/pages/workspace/content/allContents/index.tsx +++ b/src/pages/workspace/content/allContents/index.tsx @@ -18,14 +18,6 @@ import SearchBox from "../../../../components/SearchBox"; import { getContent } from "../../../../services/ContentService"; import { timeAgo } from "@/utils/Helper"; -interface content { - name: string; - status: string; - lastUpdatedOn: string; - appIcon: string; - contentType: string; -} - const AllContentsPage = () => { const theme = useTheme(); @@ -76,42 +68,17 @@ const AllContentsPage = () => { useEffect(() => { const getContentList = async () => { try { - const reqBody = { - request: { - filters: { - status: [ - "Draft", - "FlagDraft", - "Review", - "Processing", - "Live", - "Unlisted", - "FlagReview", - ], - createdBy: "84721b4a-6536-4cb0-b8c3-57583ef4cada", - primaryCategory: [ - "Course Assessment", - "eTextbook", - "Explanation Content", - "Learning Resource", - "Practice Question Set", - "Teacher Resource", - "Exam Question", - "Content Playlist", - "Course", - "Digital Textbook", - "Question paper", - ], - }, - offset: 0, - limit: 9, - query: "", - sort_by: { - lastUpdatedOn: "desc", - }, - }, - }; - const response = await getContent(reqBody); + const status = [ + "Draft", + "FlagDraft", + "Review", + "Processing", + "Live", + "Unlisted", + "FlagReview", + ]; + + const response = await getContent(status); const contentList = response?.content || []; setContentList(contentList); } catch (error) { diff --git a/src/pages/workspace/content/draft/index.tsx b/src/pages/workspace/content/draft/index.tsx index c756234..c5b1bea 100644 --- a/src/pages/workspace/content/draft/index.tsx +++ b/src/pages/workspace/content/draft/index.tsx @@ -1,33 +1,9 @@ -import React, { useMemo, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import Layout from "../../../../components/Layout"; -import { Typography, Box, Grid, TablePagination } from "@mui/material"; +import { Typography, Box, TablePagination } from "@mui/material"; import CourseCard from "../../../../components/CourseCard"; import SearchBox from "../../../../components/SearchBox"; - -// Sample data for draft contents -const draftData = [ - { - title: "Home Science", - description: "Learn about home science basics.", - type: "Course", - imageUrl: "", // URL for image if available, else empty - status: "draft", // Status of the content - }, - { - title: "Test1", - description: "Practice question set for Test1.", - type: "Question Set", - imageUrl: "", - status: "draft", - }, - { - title: "", - description: "", - type: "eBook", - imageUrl: "", - status: "draft", - }, -]; +import { getContent } from "@/services/ContentService"; const DraftPage = () => { const [selectedKey, setSelectedKey] = useState("draft"); @@ -36,6 +12,7 @@ const DraftPage = () => { const [searchTerm, setSearchTerm] = useState(""); const [filter, setFilter] = useState("all"); const [sortBy, setSortBy] = useState("updated"); + const [contentList, setContentList] = React.useState([]); const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage); @@ -62,21 +39,34 @@ const DraftPage = () => { const filteredData = useMemo( () => - draftData.filter((content) => - content.title.toLowerCase().includes(searchTerm) + contentList.filter((content) => + content.name.toLowerCase().includes(searchTerm) ), [searchTerm] ); - const displayedCards = filteredData.slice( - page * rowsPerPage, - page * rowsPerPage + rowsPerPage - ); + // const displayedCards = filteredData.slice( + // page * rowsPerPage, + // page * rowsPerPage + rowsPerPage + // ); const handleDelete = (index: number) => { console.log(`Deleting item at index ${index}`); }; + useEffect(() => { + const getDraftContentList = async () => { + try { + const response = await getContent(["Draft", "FlagDraft"]); + const contentList = response?.content || []; + setContentList(contentList); + } catch (error) { + console.log(error); + } + }; + getDraftContentList(); + }, []); + return ( @@ -87,13 +77,13 @@ const DraftPage = () => { - {displayedCards.map((content, index) => ( + {contentList.map((content, index) => ( { }} > handleDelete(index)} /> @@ -120,7 +108,7 @@ const DraftPage = () => { { const [selectedKey, setSelectedKey] = useState("publish"); const [searchTerm, setSearchTerm] = useState(""); const [filter, setFilter] = useState("all"); const [sortBy, setSortBy] = useState("updated"); + const [contentList, setContentList] = React.useState([]); const handleSearch = (search: string) => { setSearchTerm(search.toLowerCase()); @@ -48,8 +26,8 @@ const PublishPage = () => { const filteredData = useMemo( () => - PublishData.filter((content) => - content.title.toLowerCase().includes(searchTerm) + contentList.filter((content) => + content.name.toLowerCase().includes(searchTerm) ), [searchTerm] ); @@ -64,6 +42,19 @@ const PublishPage = () => { console.log(`Deleting item at index ${index}`); }; + useEffect(() => { + const getPublishContentList = async () => { + try { + const response = await getContent(["Live"]); + const contentList = response?.content || response?.QuestionSet; + setContentList(contentList); + } catch (error) { + console.log(error); + } + }; + getPublishContentList(); + }, [searchTerm]); + return ( @@ -74,13 +65,13 @@ const PublishPage = () => { - {displayedCards.map((content, index) => ( + {contentList.map((content, index) => ( { }} > handleDelete(index)} /> diff --git a/src/pages/workspace/content/submitted/index.tsx b/src/pages/workspace/content/submitted/index.tsx index d4e789f..d2fcf44 100644 --- a/src/pages/workspace/content/submitted/index.tsx +++ b/src/pages/workspace/content/submitted/index.tsx @@ -1,38 +1,16 @@ -import React, { useMemo, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import Layout from "../../../../components/Layout"; import { Typography, Box } from "@mui/material"; import CourseCard from "../../../../components/CourseCard"; import SearchBox from "../../../../components/SearchBox"; - -const ReviewData = [ - { - title: "Home Science", - description: "Learn about home science basics.", - type: "Course", - imageUrl: "", - status: "submittedForReview", - }, - { - title: "Test1", - description: "Practice question set for Test1.", - type: "Question Set", - imageUrl: "", - status: "submittedForReview", - }, - { - title: "", - description: "", - type: "eBook", - imageUrl: "", - status: "submittedForReview", - }, -]; +import { getContent } from "@/services/ContentService"; const SubmittedForReviewPage = () => { const [selectedKey, setSelectedKey] = useState("submitted"); const [filter, setFilter] = useState("all"); const [sortBy, setSortBy] = useState("updated"); const [searchTerm, setSearchTerm] = useState(""); + const [contentList, setContentList] = React.useState([]); const handleSearch = (search: string) => { setSearchTerm(search.toLowerCase()); @@ -48,8 +26,8 @@ const SubmittedForReviewPage = () => { const filteredData = useMemo( () => - ReviewData.filter((content) => - content.title.toLowerCase().includes(searchTerm) + contentList.filter((content) => + content?.name.toLowerCase().includes(searchTerm) ), [searchTerm] ); @@ -64,6 +42,19 @@ const SubmittedForReviewPage = () => { console.log(`Deleting item at index ${index}`); }; + useEffect(() => { + const getReviewContentList = async () => { + try { + const response = await getContent(["Review", "FlagReview"]); + const contentList = response?.content || response?.QuestionSet; + setContentList(contentList); + } catch (error) { + console.log(error); + } + }; + getReviewContentList(); + }, [searchTerm]); + return ( @@ -76,13 +67,13 @@ const SubmittedForReviewPage = () => { - {displayedCards.map((content, index) => ( + {contentList.map((content, index) => ( { }} > handleDelete(index)} /> diff --git a/src/services/ContentService.ts b/src/services/ContentService.ts index 663ec69..94bd00d 100644 --- a/src/services/ContentService.ts +++ b/src/services/ContentService.ts @@ -1,8 +1,49 @@ import { post } from "./RestClient"; -export const getContent = async (reqBody: any) => { +const defaultReqBody = { + request: { + filters: { + createdBy: "84721b4a-6536-4cb0-b8c3-57583ef4cada", + primaryCategory: [ + "Course Assessment", + "eTextbook", + "Explanation Content", + "Learning Resource", + "Practice Question Set", + "Teacher Resource", + "Exam Question", + "Content Playlist", + "Course", + "Digital Textbook", + "Question paper", + ], + }, + offset: 0, + limit: 9, + query: "", + sort_by: { + lastUpdatedOn: "desc", + }, + }, +}; + +const getReqBodyWithStatus = (status: string[]) => { + return { + ...defaultReqBody, + request: { + ...defaultReqBody.request, + filters: { + ...defaultReqBody.request.filters, + status, + }, + }, + }; +}; + +export const getContent = async (status: string[]) => { const apiURL = "https://sunbirdsaas.com/api/content/v1/search"; try { + const reqBody = getReqBodyWithStatus(status); const response = await post(apiURL, reqBody); return response?.data?.result; } catch (error) { diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 7aa248e..4dc95bb 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -6,3 +6,12 @@ interface SidebarProps { interface DashboardContentProps { selectedKey: any; } + +interface content { + name: string; + status: string; + lastUpdatedOn: string; + appIcon: string; + contentType: string; + description?: string; +}