-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from AkshataKatwal16/page-issue
Issue feat: Add discover content tab
- Loading branch information
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
229 changes: 229 additions & 0 deletions
229
src/pages/workspace/content/discover-contents/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
import React, { useEffect, useMemo, useState, useCallback } from "react"; | ||
import Layout from "../../../../components/Layout"; | ||
import { | ||
Typography, | ||
Box, | ||
Table, | ||
TableHead, | ||
TableBody, | ||
TableRow, | ||
TableCell, | ||
TablePagination, | ||
IconButton, | ||
useTheme, | ||
} from "@mui/material"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import UpReviewTinyImage from "@mui/icons-material/LibraryBooks"; | ||
import SearchBox from "../../../../components/SearchBox"; | ||
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"; | ||
import PaginationComponent from "@/components/PaginationComponent"; | ||
import { LIMIT } from "@/utils/app.constant"; | ||
import WorkspaceText from "@/components/WorkspaceText"; | ||
import { Table as KaTable } from 'ka-table'; | ||
import { DataType } from 'ka-table/enums'; | ||
import "ka-table/style.css"; | ||
import KaTableComponent from "@/components/KaTableComponent"; | ||
import useSharedStore from "@/utils/useSharedState"; | ||
// const columns = [ | ||
// { key: 'name', title: 'Content', dataType: DataType.String, width: "450px" }, | ||
// { key: 'lastUpdatedOn', title: 'Last Updated', dataType: DataType.String, width: "300px" }, | ||
// { key: 'status', title: 'Status', dataType: DataType.String, width: "300px" }, | ||
// { key: 'contentAction', title: 'Action', dataType: DataType.String, width: "200px" }, | ||
|
||
// ] | ||
const columns = [ | ||
{ key: 'name', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "450px" }, | ||
{ key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "250px" }, | ||
{ key: 'status', title: 'STATUS', dataType: DataType.String, width: "100px" }, | ||
{ key: 'lastUpdatedOn', title: 'LAST MODIFIED', dataType: DataType.String, width: "180px" }, | ||
{ key: 'contentAction', title: 'ACTION', dataType: DataType.String, width: "100px" }, | ||
{ key: 'create-by', title: 'CREATED BY', dataType: DataType.String, width: "100px" }, | ||
|
||
|
||
] | ||
const ContentsPage = () => { | ||
const theme = useTheme<any>(); | ||
|
||
const [selectedKey, setSelectedKey] = useState("contents"); | ||
const [page, setPage] = useState(0); | ||
const [rowsPerPage, setRowsPerPage] = useState(10); | ||
const [searchTerm, setSearchTerm] = useState(""); | ||
const [filter, setFilter] = useState<string[]>([]); | ||
const [sortBy, setSortBy] = useState("Modified On"); | ||
const [contentList, setContentList] = React.useState<content[]>([]); | ||
const [data, setData] = React.useState<any[]>([]); | ||
|
||
const [loading, setLoading] = useState(false); | ||
const [contentDeleted, setContentDeleted] = React.useState(false); | ||
const fetchContentAPI = useSharedStore( | ||
(state: any) => state.fetchContentAPI | ||
); | ||
const [debouncedSearchTerm, setDebouncedSearchTerm] = | ||
useState<string>(searchTerm); | ||
const [totalCount, setTotalCount] = useState(0); | ||
|
||
const handleChangePage = (event: unknown, newPage: number) => { | ||
setPage(newPage - 1); | ||
}; | ||
|
||
const handleChangeRowsPerPage = ( | ||
event: React.ChangeEvent<HTMLInputElement> | ||
) => { | ||
setRowsPerPage(parseInt(event.target.value, 10)); | ||
setPage(0); | ||
}; | ||
|
||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedSearchTerm(searchTerm); | ||
}, 300); | ||
|
||
return () => { | ||
clearTimeout(handler); | ||
}; | ||
}, [searchTerm]); | ||
|
||
const handleSearch = (term: string) => { | ||
setSearchTerm(term); | ||
}; | ||
|
||
const handleFilterChange = (filter: string[]) => { | ||
setFilter(filter); | ||
}; | ||
|
||
const handleSortChange = (sortBy: string) => { | ||
console.log("sortBy", sortBy) | ||
setSortBy(sortBy); | ||
}; | ||
|
||
|
||
useEffect(() => { | ||
const getContentList = async () => { | ||
try { | ||
setLoading(true); | ||
const status = [ | ||
// "Draft", | ||
// "FlagDraft", | ||
// "Review", | ||
// "Processing", | ||
"Live", | ||
// "Unlisted", | ||
// "FlagReview", | ||
]; | ||
const query = debouncedSearchTerm || ""; | ||
const primaryCategory = filter.length ? filter : []; | ||
const order = sortBy === "Created On" ? "asc" : "desc"; | ||
const sort_by = { | ||
lastUpdatedOn: order, | ||
}; | ||
const offset = page * LIMIT; | ||
const contentType="upReview" | ||
|
||
const response = await getContent( | ||
status, | ||
query, | ||
LIMIT, | ||
offset, | ||
primaryCategory, | ||
sort_by, | ||
contentType | ||
); | ||
const contentList = (response?.content || []).concat( | ||
response?.QuestionSet || [] | ||
); | ||
setContentList(contentList); | ||
setTotalCount(response?.count); | ||
setLoading(false); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
getContentList(); | ||
}, [debouncedSearchTerm, filter,fetchContentAPI, sortBy, page]); | ||
|
||
useEffect(() => { | ||
const filteredArray = contentList.map(item => ({ | ||
image: item?.appIcon, | ||
contentType: item.primaryCategory, | ||
name: item.name, | ||
primaryCategory: item.primaryCategory, | ||
lastUpdatedOn: timeAgo(item.lastUpdatedOn), | ||
status: item.status, | ||
identifier: item.identifier, | ||
mimeType: item.mimeType, | ||
mode: item.mode, | ||
creator: item.creator | ||
|
||
|
||
})); | ||
setData(filteredArray) | ||
console.log(filteredArray) | ||
}, [contentList]); | ||
|
||
|
||
|
||
const filteredData = useMemo( | ||
() => | ||
contentList?.filter((content) => | ||
content?.name.toLowerCase().includes(debouncedSearchTerm.toLowerCase()) | ||
), | ||
[debouncedSearchTerm, contentList] | ||
); | ||
|
||
|
||
const displayedRows = filteredData.slice( | ||
page * rowsPerPage, | ||
page * rowsPerPage + rowsPerPage | ||
); | ||
|
||
console.log("contentList", contentList) | ||
return ( | ||
<Layout selectedKey={selectedKey} onSelect={setSelectedKey}> | ||
<WorkspaceText /> | ||
|
||
<Box p={3}> | ||
<Box sx={{ background: "#fff", borderRadius: '8px', boxShadow: "0px 2px 6px 2px #00000026", pb: totalCount > LIMIT ? '15px' : '0px' }}> | ||
<Box p={2}> | ||
<Typography variant="h4" sx={{ fontWeight: "bold", fontSize: "16px" }}>All My Contents</Typography> | ||
</Box> | ||
{/* <Typography mb={2}>Here you see all your content.</Typography> */} | ||
|
||
<Box mb={3}> | ||
<SearchBox | ||
placeholder="Search by title..." | ||
onSearch={handleSearch} | ||
onFilterChange={handleFilterChange} | ||
onSortChange={handleSortChange} | ||
/> | ||
</Box> | ||
{loading ? ( | ||
<Loader showBackdrop={true} loadingText={"Loading"} /> | ||
) : ( | ||
<> | ||
<Box className="table-ka-container"> | ||
<KaTableComponent columns={columns} tableTitle="discover-contents" data={data} /> | ||
</Box> | ||
</> | ||
)} | ||
{totalCount > LIMIT && ( | ||
<PaginationComponent | ||
count={Math.ceil(totalCount / LIMIT)} | ||
page={page} | ||
onPageChange={(event, newPage) => setPage(newPage - 1)} | ||
/> | ||
)} | ||
</Box> | ||
|
||
|
||
</Box> | ||
|
||
</Layout> | ||
); | ||
}; | ||
|
||
export default ContentsPage; |