diff --git a/src/components/SearchBox.tsx b/src/components/SearchBox.tsx index 882c6bd..1e3f9cd 100644 --- a/src/components/SearchBox.tsx +++ b/src/components/SearchBox.tsx @@ -23,6 +23,7 @@ import { getPrimaryCategory, } from "@/services/ContentService"; import { SortOptions, StatusOptions } from "@/utils/app.constant"; +import router from "next/router"; export interface SearchBarProps { onSearch: (value: string) => void; @@ -53,14 +54,29 @@ const SearchBox: React.FC = ({ }) => { const theme = useTheme(); const [searchTerm, setSearchTerm] = useState(value); - const [selectedFilters, setSelectedFilters] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [status, setStatus] = useState("All"); - const [state, setState] = useState("All"); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + + const [sortBy, setSortBy] = useState(sort); + const statusQuery : string = typeof router.query.status === "string" + ? router.query.status + : "All"; + const [status, setStatus] = useState(statusQuery); + const stateQuery : string = typeof router.query.state === "string" + ? router.query.state + : "All"; + const [state, setState] = useState(stateQuery); const [stateOptions, setStateOptions] = useState([]); - const [primaryCategory, setPrimaryCategory] = useState(); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [selectedFilters, setSelectedFilters] = useState(filterOption); +console.log("filterOption", filterOption); + const [primaryCategory, setPrimaryCategory] = useState(); + useEffect(() => { const PrimaryCategoryData = async () => { const response = await getPrimaryCategory(); @@ -128,23 +144,55 @@ const SearchBox: React.FC = ({ const handleFilterChange = (event: SelectChangeEvent) => { const value = event.target.value as string[]; + router.push( + { + pathname: router.pathname, + query: { ...router.query, page: 1 , filterOptions: JSON.stringify(value)}, + }, + undefined, + { shallow: true } + ); setSelectedFilters(value); onFilterChange && onFilterChange(value); }; const handleSortChange = (event: SelectChangeEvent) => { const value = event.target.value as string; + router.push( + { + pathname: router.pathname, + query: { ...router.query, sort: value}, + }, + undefined, + { shallow: true } + ); setSortBy(value); onSortChange && onSortChange(value); }; const handleStatusChange = (event: SelectChangeEvent) => { const value = event.target.value as string; + router.push( + { + pathname: router.pathname, + query: { ...router.query, status: value}, + }, + undefined, + { shallow: true } + ); setStatus(value); onStatusChange && onStatusChange(value); }; const handleStateChange = (event: SelectChangeEvent) => { const value = event.target.value as string; + router.push( + { + pathname: router.pathname, + query: { ...router.query, state: value}, + }, + undefined, + { shallow: true } + ); setState(value); onStateChange && onStateChange(value); }; diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index a561981..ea8567a 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -58,6 +58,7 @@ const Sidebar: React.FC = ({ selectedKey, onSelect }) => { const handleNavigation = (key: string) => { console.log(key); router.push(`/workspace/content/${key}`); + localStorage.setItem("selectedFilters", JSON.stringify([])) onSelect(key); if (isMobile) { setDrawerOpen(false); // Close drawer after selecting in mobile view diff --git a/src/pages/workspace/content/allContents/index.tsx b/src/pages/workspace/content/allContents/index.tsx index 398b7ed..5f7f02d 100644 --- a/src/pages/workspace/content/allContents/index.tsx +++ b/src/pages/workspace/content/allContents/index.tsx @@ -1,4 +1,10 @@ -import React, { useEffect, useMemo, useState, useCallback } from "react"; +import React, { + useEffect, + useMemo, + useState, + useCallback, + useRef, +} from "react"; import Layout from "../../../../components/Layout"; import { Typography, @@ -24,8 +30,8 @@ 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 { 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"; @@ -37,14 +43,32 @@ import useSharedStore from "@/utils/useSharedState"; // ] const columns = [ - { key: 'title_and_description', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "450px" }, - { key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "200px" }, - { 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: "title_and_description", + title: "TITLE & DESCRIPTION", + dataType: DataType.String, + width: "450px", + }, + { + key: "contentType", + title: "CONTENT TYPE", + dataType: DataType.String, + width: "200px", + }, + { 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", + }, +]; const AllContentsPage = () => { const theme = useTheme(); @@ -52,22 +76,31 @@ const AllContentsPage = () => { const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); const [searchTerm, setSearchTerm] = useState(""); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [statusBy, setStatusBy] = useState("All"); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const statusQuery : string = typeof router.query.status === "string" + ? router.query.status + : "All"; + const [statusBy, setStatusBy] = useState(statusQuery); - const [contentList, setContentList] = React.useState([]); + const [contentList, setContentList] = React.useState([]); const [data, setData] = React.useState([]); const [loading, setLoading] = useState(false); const [contentDeleted, setContentDeleted] = React.useState(false); - const fetchContentAPI = useSharedStore( - (state: any) => state.fetchContentAPI - ); + const prevFilterRef = useRef(filter); + + const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); const [totalCount, setTotalCount] = useState(0); - + const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage - 1); }; @@ -98,19 +131,18 @@ const AllContentsPage = () => { }; const handleSortChange = (sortBy: string) => { - console.log("sortBy", sortBy) + console.log("sortBy", sortBy); setSortBy(sortBy); }; const handleStatusChange = (statusBy: string) => { setStatusBy(statusBy); }; - useEffect(() => { const getContentList = async () => { try { setLoading(true); - let status=[ + let status = [ "Draft", "FlagDraft", "Review", @@ -119,41 +151,62 @@ const AllContentsPage = () => { "Unlisted", "FlagReview", ]; - if (statusBy === "" || statusBy === "All") { - status = [ - "Draft", - "FlagDraft", - "Review", - "Processing", - "Live", - "Unlisted", - "FlagReview", - ]; - } - else if (statusBy === "Live") { - status = ["Live"]; - } - else if (statusBy === "Review") { - status = ["Review"]; - } - else if (statusBy === "Draft") { - status = ["Draft"]; - } - else if (statusBy === "Unlisted") { - status = ["Unlisted"]; - } - else if (statusBy === "FlagReview") { - status = ["FlagReview"]; + + switch (statusBy) { + case "": + case "All": + status = [ + "Draft", + "FlagDraft", + "Review", + "Processing", + "Live", + "Unlisted", + "FlagReview", + ]; + break; + case "Live": + status = ["Live"]; + break; + case "Review": + status = ["Review"]; + break; + case "Draft": + status = ["Draft"]; + break; + case "Unlisted": + status = ["Unlisted"]; + break; + case "FlagReview": + status = ["FlagReview"]; + break; + default: + status = [ + "Draft", + "FlagDraft", + "Review", + "Processing", + "Live", + "Unlisted", + "FlagReview", + ];; } - + + const query = debouncedSearchTerm || ""; - const primaryCategory = filter.length ? filter : []; - const order = sortBy === "Created On" ? "asc" : "desc"; + const primaryCategory = filter.length ? filter : []; + const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order, }; - const offset =debouncedSearchTerm!==""? 0: page * LIMIT; - console.log("seraching", debouncedSearchTerm) + let offset = debouncedSearchTerm !== "" ? 0 : page * LIMIT; + if (prevFilterRef.current !== filter) { + offset = 0; + setPage(0); + + prevFilterRef.current = filter; + } + console.log("seraching", debouncedSearchTerm); const response = await getContent( status, query, @@ -173,10 +226,10 @@ const AllContentsPage = () => { } }; getContentList(); - }, [debouncedSearchTerm, filter,fetchContentAPI, sortBy, statusBy, page]); + }, [debouncedSearchTerm, filter, fetchContentAPI, sortBy, statusBy, page]); useEffect(() => { - const filteredArray = contentList.map(item => ({ + const filteredArray = contentList.map((item) => ({ image: item?.appIcon, contentType: item.primaryCategory, name: item.name, @@ -186,15 +239,12 @@ const AllContentsPage = () => { identifier: item.identifier, mimeType: item.mimeType, mode: item.mode, - description: item?.description - + description: item?.description, })); - setData(filteredArray) - console.log(filteredArray) + setData(filteredArray); + console.log(filteredArray); }, [contentList]); - - const filteredData = useMemo( () => contentList?.filter((content) => @@ -203,21 +253,32 @@ const AllContentsPage = () => { [debouncedSearchTerm, contentList] ); - const displayedRows = filteredData.slice( page * rowsPerPage, page * rowsPerPage + rowsPerPage - ); - - console.log("contentList", contentList) + ); + + console.log("contentList", contentList); return ( - + - LIMIT ? '15px' : '0px' }}> + LIMIT ? "15px" : "0px", + }} + > - All My Contents + + All My Contents + {/* Here you see all your content. */} @@ -231,16 +292,20 @@ const AllContentsPage = () => { allContents={true} /> - {loading ? ( + {loading ? ( ) : ( <> - - - - + + + + )} - {totalCount > LIMIT && ( + {totalCount > LIMIT && ( { /> )} - - - ); }; diff --git a/src/pages/workspace/content/discover-contents/index.tsx b/src/pages/workspace/content/discover-contents/index.tsx index 3b2af00..1a2f727 100644 --- a/src/pages/workspace/content/discover-contents/index.tsx +++ b/src/pages/workspace/content/discover-contents/index.tsx @@ -1,4 +1,10 @@ -import React, { useEffect, useMemo, useState, useCallback } from "react"; +import React, { + useEffect, + useMemo, + useState, + useCallback, + useRef, +} from "react"; import Layout from "../../../../components/Layout"; import { Typography, @@ -24,8 +30,8 @@ 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 { 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"; @@ -37,17 +43,35 @@ import useSharedStore from "@/utils/useSharedState"; // ] const columns = [ - { key: 'title_and_description', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "350px" }, - { key: 'create-by', title: 'CREATED BY', dataType: DataType.String, width: "100px" }, + { + key: "title_and_description", + title: "TITLE & DESCRIPTION", + dataType: DataType.String, + width: "350px", + }, + { + key: "create-by", + title: "CREATED BY", + dataType: DataType.String, + width: "100px", + }, - { key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "100px" }, - { key: 'state', title: 'STATE', dataType: DataType.String, width: "100px" }, + { + key: "contentType", + title: "CONTENT TYPE", + dataType: DataType.String, + width: "100px", + }, + { key: "state", title: "STATE", dataType: DataType.String, width: "100px" }, - { key: 'status', title: 'STATUS', dataType: DataType.String, width: "100px" }, - { key: 'lastUpdatedOn', title: 'LAST MODIFIED', dataType: DataType.String, width: "100px" }, - - -] + { key: "status", title: "STATUS", dataType: DataType.String, width: "100px" }, + { + key: "lastUpdatedOn", + title: "LAST MODIFIED", + dataType: DataType.String, + width: "100px", + }, +]; const ContentsPage = () => { const theme = useTheme(); @@ -55,21 +79,29 @@ const ContentsPage = () => { const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); const [searchTerm, setSearchTerm] = useState(""); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [contentList, setContentList] = React.useState([]); + + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const [contentList, setContentList] = React.useState([]); const [data, setData] = React.useState([]); + const prevFilterRef = useRef(filter); const [loading, setLoading] = useState(false); const [contentDeleted, setContentDeleted] = React.useState(false); - const fetchContentAPI = useSharedStore( - (state: any) => state.fetchContentAPI - ); + const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); const [totalCount, setTotalCount] = useState(0); - const [state, setState] = useState("All"); - + const stateQuery : string = typeof router.query.state === "string" + ? router.query.state + : "All"; + const [state, setState] = useState(stateQuery); const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage - 1); }; @@ -100,11 +132,11 @@ const ContentsPage = () => { }; const handleSortChange = (sortBy: string) => { - console.log("sortBy", sortBy) + console.log("sortBy", sortBy); setSortBy(sortBy); }; const handleStateChange = (state: string) => { - setState(state) + setState(state); }; useEffect(() => { @@ -121,39 +153,31 @@ const ContentsPage = () => { // "FlagReview", ]; const query = debouncedSearchTerm || ""; - const primaryCategory = filter.length ? filter : []; + + const primaryCategory = filter.length ? filter : []; const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order, }; - const offset =debouncedSearchTerm!==""? 0 : page * LIMIT; - - const contentType="discover-contents" -let response; -if(state!=="All") -{ - response = await getContent( - status, - query, - LIMIT, - offset, - primaryCategory, - sort_by, - contentType, - state - ); -} -else{ - response = await getContent( - status, - query, - LIMIT, - offset, - primaryCategory, - sort_by, - contentType - ); -} + let offset = debouncedSearchTerm !== "" ? 0 : page * LIMIT; + if (prevFilterRef.current !== filter) { + offset = 0; + setPage(0); + + prevFilterRef.current = filter; + } + const contentType = "discover-contents"; + + const response = await getContent( + status, + query, + LIMIT, + offset, + primaryCategory, + sort_by, + contentType, + state !== "All" ? state : undefined + ); const contentList = (response?.content || []).concat( response?.QuestionSet || [] @@ -166,10 +190,10 @@ else{ } }; getContentList(); - }, [debouncedSearchTerm, filter,fetchContentAPI, sortBy, state, page]); + }, [debouncedSearchTerm, filter, fetchContentAPI, sortBy, state, page]); useEffect(() => { - const filteredArray = contentList.map(item => ({ + const filteredArray = contentList.map((item) => ({ image: item?.appIcon, contentType: item.primaryCategory, name: item.name, @@ -182,14 +206,12 @@ else{ creator: item.creator, description: item?.description, state: item?.state, - author: item.author + author: item.author, })); - setData(filteredArray) - console.log(filteredArray) + setData(filteredArray); + console.log(filteredArray); }, [contentList]); - - const filteredData = useMemo( () => contentList?.filter((content) => @@ -198,21 +220,32 @@ else{ [debouncedSearchTerm, contentList] ); - const displayedRows = filteredData.slice( page * rowsPerPage, page * rowsPerPage + rowsPerPage - ); - - console.log("contentList", contentList) + ); + + console.log("contentList", contentList); return ( - + - LIMIT ? '15px' : '0px' }}> + LIMIT ? "15px" : "0px", + }} + > - Discover Contents + + Discover Contents + {/* Here you see all your content. */} @@ -226,28 +259,29 @@ else{ discoverContents={true} /> - {loading ? ( + {loading ? ( ) : ( <> - - - - + + + + )} - {totalCount > LIMIT && ( + {totalCount > LIMIT && ( setPage(newPage - 1)} + onPageChange={(event, newPage) => setPage(newPage - 1)} /> )} - - - ); }; diff --git a/src/pages/workspace/content/draft/index.tsx b/src/pages/workspace/content/draft/index.tsx index e1ee0a2..8aa5da0 100644 --- a/src/pages/workspace/content/draft/index.tsx +++ b/src/pages/workspace/content/draft/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState } from "react"; +import React, { useEffect, useMemo, useRef, useState } from "react"; import Layout from "../../../../components/Layout"; import { Typography, @@ -21,35 +21,55 @@ import { LIMIT } from "@/utils/app.constant"; import { useRouter } from "next/router"; import { MIME_TYPE } from "@/utils/app.config"; import WorkspaceText from "@/components/WorkspaceText"; -import { DataType } from 'ka-table/enums'; +import { DataType } from "ka-table/enums"; import KaTableComponent from "@/components/KaTableComponent"; -import Paper from '@mui/material/Paper'; +import Paper from "@mui/material/Paper"; import { timeAgo } from "@/utils/Helper"; import useSharedStore from "@/utils/useSharedState"; const columns = [ - { key: 'title_and_description', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "450px" }, - { key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "200px" }, - { key: 'lastUpdatedOn', title: 'LAST MODIFIED', dataType: DataType.String, width: "180px" }, - { key: 'action', title: 'ACTION', dataType: DataType.String, width: "100px" }, - - -] + { + key: "title_and_description", + title: "TITLE & DESCRIPTION", + dataType: DataType.String, + width: "450px", + }, + { + key: "contentType", + title: "CONTENT TYPE", + dataType: DataType.String, + width: "200px", + }, + { + key: "lastUpdatedOn", + title: "LAST MODIFIED", + dataType: DataType.String, + width: "180px", + }, + { key: "action", title: "ACTION", dataType: DataType.String, width: "100px" }, +]; const DraftPage = () => { const [selectedKey, setSelectedKey] = useState("draft"); + const router = useRouter(); + const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(5); const [searchTerm, setSearchTerm] = useState(""); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [contentList, setContentList] = React.useState([]); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const [contentList, setContentList] = React.useState([]); const [contentDeleted, setContentDeleted] = React.useState(false); const [loading, setLoading] = useState(false); const [totalCount, setTotalCount] = useState(0); const [data, setData] = React.useState([]); - const fetchContentAPI = useSharedStore( - (state: any) => state.fetchContentAPI - ); + const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI); + const prevFilterRef = useRef(filter); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); @@ -76,10 +96,10 @@ const DraftPage = () => { status: item.status, identifier: item.identifier, mimeType: item.mimeType, - mode: item.mode + mode: item.mode, })); - setData(filteredArray) - console.log(filteredArray) + setData(filteredArray); + console.log(filteredArray); }, [contentList]); const handleSearch = (search: string) => { @@ -99,17 +119,20 @@ const DraftPage = () => { setContentDeleted((prev) => !prev); }; - const router = useRouter(); - - useEffect(() => { const getDraftContentList = async () => { try { setLoading(true); const query = debouncedSearchTerm || ""; - const offset =debouncedSearchTerm!==""? 0 : page * LIMIT; - const primaryCategory = filter.length ? filter : []; + let offset = debouncedSearchTerm !== "" ? 0 : page * LIMIT; + + const primaryCategory =filter.length? filter: []; + if (prevFilterRef.current !== filter) { + offset = 0; + setPage(0); + prevFilterRef.current = filter; + } const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order }; const response = await getContent( @@ -132,14 +155,27 @@ const DraftPage = () => { } }; getDraftContentList(); - }, [debouncedSearchTerm, filter, sortBy, contentDeleted, fetchContentAPI,page]); - + }, [ + debouncedSearchTerm, + filter, + sortBy, + contentDeleted, + fetchContentAPI, + page, + ]); return ( - - LIMIT ? '15px' : '0px' }}> + + LIMIT ? "15px" : "0px", + }} + > { onSortChange={handleSortChange} /> - {loading ? ( + {loading ? ( - ) :(<> - - - - + ) : ( + <> + + + + )} {totalCount > LIMIT && ( setPage(newPage - 1)} + onPageChange={(event, newPage) => setPage(newPage - 1)} /> )} - ); }; diff --git a/src/pages/workspace/content/publish/index.tsx b/src/pages/workspace/content/publish/index.tsx index ff55a1c..8554d8b 100644 --- a/src/pages/workspace/content/publish/index.tsx +++ b/src/pages/workspace/content/publish/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState } from "react"; +import React, { useEffect, useMemo, useRef, useState } from "react"; import Layout from "../../../../components/Layout"; import { Typography, @@ -21,39 +21,58 @@ import { LIMIT } from "@/utils/app.constant"; import { useRouter } from "next/router"; import { MIME_TYPE } from "@/utils/app.config"; import WorkspaceText from "@/components/WorkspaceText"; -import { DataType } from 'ka-table/enums'; +import { DataType } from "ka-table/enums"; import KaTableComponent from "@/components/KaTableComponent"; import { timeAgo } from "@/utils/Helper"; import useSharedStore from "@/utils/useSharedState"; const columns = [ - { key: 'title_and_description', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "450px" }, - { key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "200px" }, + { + key: "title_and_description", + title: "TITLE & DESCRIPTION", + dataType: DataType.String, + width: "450px", + }, + { + key: "contentType", + title: "CONTENT TYPE", + dataType: DataType.String, + width: "200px", + }, // { key: 'status', title: 'STATUS', dataType: DataType.String, width: "100px" }, - { key: 'lastUpdatedOn', title: 'LAST MODIFIED', dataType: DataType.String, width: "180px" }, - { key: 'action', title: 'ACTION', dataType: DataType.String, width: "100px" }, - - -] + { + key: "lastUpdatedOn", + title: "LAST MODIFIED", + dataType: DataType.String, + width: "180px", + }, + { key: "action", title: "ACTION", dataType: DataType.String, width: "100px" }, +]; const PublishPage = () => { + const router = useRouter(); + const [selectedKey, setSelectedKey] = useState("publish"); const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(5); const [searchTerm, setSearchTerm] = useState(""); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [contentList, setContentList] = React.useState([]); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const [contentList, setContentList] = React.useState([]); const [contentDeleted, setContentDeleted] = React.useState(false); const [loading, setLoading] = useState(false); const [totalCount, setTotalCount] = useState(0); const [data, setData] = React.useState([]); - const fetchContentAPI = useSharedStore( - (state: any) => state.fetchContentAPI - ); + const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); - const router = useRouter(); + const prevFilterRef = useRef(filter); useEffect(() => { const handler = setTimeout(() => { @@ -76,10 +95,10 @@ const PublishPage = () => { status: item.status, identifier: item.identifier, mimeType: item.mimeType, - mode: item.mode + mode: item.mode, })); - setData(filteredArray) - console.log(filteredArray) + setData(filteredArray); + console.log(filteredArray); }, [contentList]); const handleSearch = (search: string) => { setSearchTerm(search.toLowerCase()); @@ -93,8 +112,6 @@ const PublishPage = () => { setSortBy(sortBy); }; - - const openEditor = (content: any) => { const identifier = content?.identifier; const mode = "read"; @@ -119,8 +136,15 @@ const PublishPage = () => { try { setLoading(true); const query = debouncedSearchTerm || ""; - const offset =debouncedSearchTerm!==""? 0 : page * LIMIT; + let offset = debouncedSearchTerm !== "" ? 0 : page * LIMIT; + const primaryCategory = filter.length ? filter : []; + if (prevFilterRef.current !== filter) { + offset = 0; + setPage(0); + + prevFilterRef.current = filter; + } const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order }; const response = await getContent( @@ -143,14 +167,27 @@ const PublishPage = () => { } }; getPublishContentList(); - }, [debouncedSearchTerm, filter, sortBy,fetchContentAPI, contentDeleted, page]); - + }, [ + debouncedSearchTerm, + filter, + sortBy, + fetchContentAPI, + contentDeleted, + page, + ]); return ( - LIMIT ? '15px' : '0px' }} > + LIMIT ? "15px" : "0px", + }} + > { > Published - { /> {/* Here you see all your published content. */} -{loading ? ( + {loading ? ( - ) : (<> - - - - )} - {totalCount > LIMIT && ( + ) : ( + <> + + + + + )} + {totalCount > LIMIT && ( setPage(newPage - 1)} + onPageChange={(event, newPage) => setPage(newPage - 1)} /> )} - ); diff --git a/src/pages/workspace/content/submitted/index.tsx b/src/pages/workspace/content/submitted/index.tsx index b2e6f45..269ed34 100644 --- a/src/pages/workspace/content/submitted/index.tsx +++ b/src/pages/workspace/content/submitted/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import Layout from "../../../../components/Layout"; import { Typography, @@ -21,24 +21,43 @@ import { LIMIT } from "@/utils/app.constant"; import { MIME_TYPE } from "@/utils/app.config"; import router from "next/router"; import WorkspaceText from "@/components/WorkspaceText"; -import { DataType } from 'ka-table/enums'; +import { DataType } from "ka-table/enums"; import KaTableComponent from "@/components/KaTableComponent"; import { timeAgo } from "@/utils/Helper"; import useSharedStore from "@/utils/useSharedState"; const columns = [ - { key: 'title_and_description', title: 'TITLE & DESCRIPTION', dataType: DataType.String, width: "450px" }, - { key: 'contentType', title: 'CONTENT TYPE', dataType: DataType.String, width: "200px" }, + { + key: "title_and_description", + title: "TITLE & DESCRIPTION", + dataType: DataType.String, + width: "450px", + }, + { + key: "contentType", + title: "CONTENT TYPE", + dataType: DataType.String, + width: "200px", + }, // { key: 'status', title: 'STATUS', dataType: DataType.String, width: "100px" }, - { key: 'lastUpdatedOn', title: 'LAST MODIFIED', dataType: DataType.String, width: "180px" }, - { key: 'action', title: 'ACTION', dataType: DataType.String, width: "100px" }, - - -] + { + key: "lastUpdatedOn", + title: "LAST MODIFIED", + dataType: DataType.String, + width: "180px", + }, + { key: "action", title: "ACTION", dataType: DataType.String, width: "100px" }, +]; const SubmittedForReviewPage = () => { const [selectedKey, setSelectedKey] = useState("submitted"); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [searchTerm, setSearchTerm] = useState(""); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const [searchTerm, setSearchTerm] = useState(""); const [contentList, setContentList] = useState([]); const [loading, setLoading] = useState(false); const [contentDeleted, setContentDeleted] = useState(false); @@ -46,9 +65,9 @@ const SubmittedForReviewPage = () => { const [page, setPage] = useState(0); const [totalCount, setTotalCount] = useState(0); const [data, setData] = React.useState([]); - const fetchContentAPI = useSharedStore( - (state: any) => state.fetchContentAPI - ); + const fetchContentAPI = useSharedStore((state: any) => state.fetchContentAPI); + const prevFilterRef = useRef(filter); + useEffect(() => { const handler = setTimeout(() => { setDebouncedSearchTerm(searchTerm); @@ -70,10 +89,10 @@ const SubmittedForReviewPage = () => { status: item.status, identifier: item.identifier, mimeType: item.mimeType, - mode: item.mode + mode: item.mode, })); - setData(filteredArray) - console.log(filteredArray) + setData(filteredArray); + console.log(filteredArray); }, [contentList]); const handleSearch = (search: string) => { setSearchTerm(search.toLowerCase()); @@ -87,15 +106,19 @@ const SubmittedForReviewPage = () => { setSortBy(sortBy); }; - - useEffect(() => { const getReviewContentList = async () => { try { setLoading(true); const query = debouncedSearchTerm || ""; - const offset =debouncedSearchTerm!==""? 0 : page * LIMIT; + let offset = debouncedSearchTerm !== "" ? 0 : page * LIMIT; const primaryCategory = filter.length ? filter : []; + if (prevFilterRef.current !== filter) { + offset = 0; + setPage(0); + + prevFilterRef.current = filter; + } const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order }; const response = await getContent( @@ -118,14 +141,27 @@ const SubmittedForReviewPage = () => { } }; getReviewContentList(); - }, [debouncedSearchTerm, filter, sortBy, fetchContentAPI,contentDeleted, page]); + }, [ + debouncedSearchTerm, + filter, + sortBy, + fetchContentAPI, + contentDeleted, + page, + ]); - return ( - LIMIT ? '15px' : '0px' }}> + LIMIT ? "15px" : "0px", + }} + > { /> - {/* {loading ? ( @@ -159,16 +194,20 @@ const SubmittedForReviewPage = () => { ) : ( )} */} - {loading ? ( + {loading ? ( ) : ( - + )} - {totalCount > LIMIT && ( + {totalCount > LIMIT && ( { const [selectedKey, setSelectedKey] = useState("up-review"); - const [filter, setFilter] = useState([]); - const [sortBy, setSortBy] = useState("Modified On"); - const [searchTerm, setSearchTerm] = useState(""); + const filterOption: string[] = router.query.filterOptions + ? JSON.parse(router.query.filterOptions as string) + : []; + const [filter, setFilter] = useState(filterOption); + const sort: string = typeof router.query.sort === "string" + ? router.query.sort + : "Modified On"; + const [sortBy, setSortBy] = useState(sort); + const [searchTerm, setSearchTerm] = useState(""); const [contentList, setContentList] = useState([]); const [loading, setLoading] = useState(false); const [contentDeleted, setContentDeleted] = useState(false); @@ -48,6 +54,8 @@ const UpForReviewPage = () => { const [page, setPage] = useState(0); const [totalCount, setTotalCount] = useState(0); const [data, setData] = React.useState([]); + const prevFilterRef = useRef(filter); + const fetchContentAPI = useSharedStore( (state: any) => state.fetchContentAPI ); @@ -103,8 +111,14 @@ const UpForReviewPage = () => { try { setLoading(true); const query = debouncedSearchTerm || ""; - const offset =debouncedSearchTerm!==""? 0 : page * LIMIT; + let offset =debouncedSearchTerm!==""? 0 : page * LIMIT; const primaryCategory = filter.length ? filter : []; + if (prevFilterRef.current !== filter) { + offset=0; + setPage(0); + + prevFilterRef.current = filter; + } const order = sortBy === "Created On" ? "asc" : "desc"; const sort_by = { lastUpdatedOn: order }; const contentType="upReview"