diff --git a/frontend/src/hooks/useBookmark.js b/frontend/src/hooks/useBookmark.js
index 5a29b9d..e9cc2cb 100644
--- a/frontend/src/hooks/useBookmark.js
+++ b/frontend/src/hooks/useBookmark.js
@@ -17,7 +17,7 @@ function useBookmark() {
},
})
- const handleBookmark = (pollId) => {
+ const handleBookmark = async (pollId) => {
BookmarkMutation.mutate(pollId);
}
diff --git a/frontend/src/pages/Bookmark.jsx b/frontend/src/pages/Bookmark.jsx
index 029ad77..c11ded6 100644
--- a/frontend/src/pages/Bookmark.jsx
+++ b/frontend/src/pages/Bookmark.jsx
@@ -1,56 +1,93 @@
// BookmarkPage.js
import React from "react";
-
-const dummyBookmarks = [
- {
- id: 1,
- title: "Favorite Programming Language?",
- description: "Vote for your favorite programming language among the listed options.",
- },
- {
- id: 2,
- title: "Best Framework for Web Development?",
- description: "Share your thoughts on the best framework for web development.",
- },
- {
- id: 3,
- title: "Favorite Food?",
- description: "What's your favorite food? Vote and see the results.",
- },
-];
+import { getUserBookmarks } from "../services/getUserBookmarks";
+import { useQuery, useQueryClient } from "react-query";
+import ErrorFallback from "../components/Errors/ErrorFallback";
+import useBookmark from "../hooks/useBookmark";
+import { useNavigate } from "react-router-dom";
function Bookmark() {
+ const { handleBookmark } = useBookmark();
+ const navigator = useNavigate();
+
+ const queryClient = useQueryClient();
+
+ const { data, isLoading, isError, refetch, isSuccess } = useQuery(
+ ["bookmarks"],
+ getUserBookmarks,
+ {
+ cacheTime: 1000 * 60 * 5, // 5 minutes
+ staleTime: 1000 * 60 * 10, // 10 minutes
+ }
+ );
+
+ const handleViewPollClick = (pollId) => {
+ navigator(`/view/${pollId}`);
+ };
+
+
+ const handleRemoveBookmark = async (bookmarkId) => {
+ queryClient.setQueryData(["bookmarks"], (oldData) => {
+ return {
+ ...oldData,
+ data: oldData.data.filter((bookmark) => bookmark._id !== bookmarkId),
+ };
+ });
+ await handleBookmark(bookmarkId);
+ };
+
return (
-
Bookmarked Polls
-
-
-
-
- | # |
- Title |
- Description |
- Actions |
-
-
-
- {dummyBookmarks.map((bookmark, index) => (
-
- | {index + 1} |
- {bookmark.title} |
-
- {bookmark.description}
- |
-
-
- |
+
+ Bookmarked Polls
+
+ {isError && (
+
+
+
+ )}
+ {isLoading && }
+ {isSuccess && (
+
+
+
+
+ | # |
+ Title |
+ Description |
+ Actions |
- ))}
-
-
-
+
+
+ {data?.data?.map((bookmark, index) => (
+
+ | {index + 1} |
+
+ {bookmark.title}
+ |
+
+ {bookmark.description}
+ |
+
+
+
+ |
+
+ ))}
+
+
+
+ )}
);
}
diff --git a/frontend/src/services/getUserBookmarks.js b/frontend/src/services/getUserBookmarks.js
new file mode 100644
index 0000000..18d36c0
--- /dev/null
+++ b/frontend/src/services/getUserBookmarks.js
@@ -0,0 +1,6 @@
+import axiosInstance from "../helper/axiosInstance";
+
+export async function getUserBookmarks() {
+ const response = await axiosInstance.get("/poll/bookmarks");
+ return response.data;
+}
\ No newline at end of file