From ed029b14b92fdb6b1b92b0701e6691c3382b7073 Mon Sep 17 00:00:00 2001 From: ozdentarikcan Date: Sat, 14 Dec 2024 11:18:46 +0300 Subject: [PATCH] Implement bookmarked page --- frontend/src/routes/bookmarked.tsx | 106 +++++++++++++++++++++++++++++ frontend/src/routes/index.tsx | 5 ++ 2 files changed, 111 insertions(+) create mode 100644 frontend/src/routes/bookmarked.tsx diff --git a/frontend/src/routes/bookmarked.tsx b/frontend/src/routes/bookmarked.tsx new file mode 100644 index 00000000..00be0cb4 --- /dev/null +++ b/frontend/src/routes/bookmarked.tsx @@ -0,0 +1,106 @@ +import { DifficultyFilter } from "@/components/DifficultyFilter"; +import { useGetBookmarkedQuestions } from "@/services/api/programmingForumComponents"; +import { + DifficultyLevel, + QuestionSummary, +} from "@/services/api/programmingForumSchemas"; +import { Loader2 } from "lucide-react"; +import { useEffect, useState } from "react"; +import { useSearchParams } from "react-router-dom"; +import ErrorAlert from "../components/ErrorAlert"; +import InfiniteScroll from "../components/InfiniteScroll"; +import { QuestionCard } from "../components/QuestionCard"; + +export const BookmarkedQuestions = () => { + const [params] = useSearchParams(); + const [pageSize, setPageSize] = useState(20); + const [difficulty, setDifficulty] = useState(); + const [previousData, setPreviousData] = useState<{ + items: QuestionSummary[]; + totalItems: number; + }>({ + items: [], + totalItems: 0, + }); + + const { + data: resultList, + isLoading, + error, + } = useGetBookmarkedQuestions({}); + + useEffect(() => { + if (resultList?.data && !isLoading) { + setPreviousData(resultList.data as typeof previousData); + } + }, [resultList, isLoading]); + + if (error) { + return ; + } + + const resultListData = + (resultList?.data as typeof previousData) || previousData; + const questions = resultListData.items || []; + + const next = () => { + setPageSize(pageSize + 20); + }; + + return ( +
+
+

+ {questions.length + ? `Last ${resultListData.totalItems} bookmarked questions shown.` + : "No questions are bookmarked."} +

+
+ {!questions.length && ( +

Bookmark questions to view them here.

+ )} + +
+
+ pageSize + : false + } + isLoading={isLoading} + > + {questions.map((question) => ( + + ))} + +
+ {isLoading && ( +
+ +
+ )} +
+
+ ); +}; diff --git a/frontend/src/routes/index.tsx b/frontend/src/routes/index.tsx index fd77946f..8a869ef0 100644 --- a/frontend/src/routes/index.tsx +++ b/frontend/src/routes/index.tsx @@ -12,6 +12,7 @@ import QuestionRoute from "./question"; import { Search } from "./search"; import Signup from "./signup"; import TagPage from "./tag"; +import { BookmarkedQuestions } from "@/routes/bookmarked"; export const routes: RouteObject[] = [ { @@ -26,6 +27,10 @@ export const routes: RouteObject[] = [ path: "/login", Component: Login, }, + { + path: "/bookmarkedquestions", + Component: BookmarkedQuestions, + }, { path: "/logout", async action() {