Skip to content

Commit

Permalink
Merge pull request #32 from suvarnakale/main
Browse files Browse the repository at this point in the history
Issue #PS-2172 chore:Implementation of delete functionality changes
  • Loading branch information
itsvick authored Oct 11, 2024
2 parents 368d316 + 834e96f commit 40cdb2f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ const CourseCard: React.FC<ContentCardProps> = ({

return (
<Card
onClick={openEditor}
sx={{
height: "100%",
display: "flex",
flexDirection: "column",
width: "250px",
}}
>
<Box position="relative" onClick={openEditor}>
<Box position="relative">
<CardMedia
component="div"
sx={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Loader: React.FC<{ showBackdrop: boolean; loadingText: string }> = ({
<>
<CircularProgress color="inherit" />
<br />
<Typography variant="h2">{loadingText}...</Typography>
<Typography variant="h4">{loadingText}...</Typography>
</>
);
};
Expand Down
51 changes: 45 additions & 6 deletions src/pages/workspace/content/allContents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>();
Expand All @@ -31,6 +33,7 @@ const AllContentsPage = () => {
const [sortBy, setSortBy] = useState("updated");
const [contentList, setContentList] = React.useState<content[]>([]);
const [loading, setLoading] = useState(false);
const [contentDeleted, setContentDeleted] = React.useState(false);
const [debouncedSearchTerm, setDebouncedSearchTerm] =
useState<string>(searchTerm);

Expand Down Expand Up @@ -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 {
Expand All @@ -82,15 +98,31 @@ 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) {
console.log(error);
}
};
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(
() =>
Expand Down Expand Up @@ -132,8 +164,12 @@ const AllContentsPage = () => {
<TableBody>
{contentList?.map((content, index) => (
<TableRow key={index}>
<TableCell>
<Box display="flex" alignItems="center">
<TableCell onClick={() => openEditor(content)}>
<Box
display="flex"
alignItems="center"
sx={{ cursor: "pointer" }}
>
{content?.appIcon ? (
<img src={content?.appIcon} height={"25px"} />
) : (
Expand All @@ -156,7 +192,10 @@ const AllContentsPage = () => {
<TableCell>{content?.status}</TableCell>
<TableCell>
{content?.status === "Draft" && (
<IconButton aria-label="delete">
<IconButton
aria-label="delete"
onClick={() => handleDeleteClick(content)}
>
<DeleteIcon />
</IconButton>
)}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/content/draft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/content/publish/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/workspace/content/submitted/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 40cdb2f

Please sign in to comment.