From 26179b89bfe85457d59231ba99e7b4604c4393b4 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Jan 2025 20:45:26 +0300 Subject: [PATCH] Work at add post to blog dialog --- enshi/src/@types/BlogTypes.ts | 8 ++ enshi/src/App.tsx | 2 +- .../ArticleViewer/ArticleViewer.tsx | 64 +-------------- .../AddPostToBlogDialog.tsx | 82 +++++++++++++++++++ 4 files changed, 94 insertions(+), 62 deletions(-) create mode 100644 enshi/src/@types/BlogTypes.ts create mode 100644 enshi/src/Components/Dialogs/AddPostToBlogDialog/AddPostToBlogDialog.tsx diff --git a/enshi/src/@types/BlogTypes.ts b/enshi/src/@types/BlogTypes.ts new file mode 100644 index 0000000..f638c7e --- /dev/null +++ b/enshi/src/@types/BlogTypes.ts @@ -0,0 +1,8 @@ +export type Blog = { + blog_id: number; + user_id: number; + title: string; + description?: string; + category_id?: number; + created_at: Date; +} \ No newline at end of file diff --git a/enshi/src/App.tsx b/enshi/src/App.tsx index 29bf349..cbcc6d9 100644 --- a/enshi/src/App.tsx +++ b/enshi/src/App.tsx @@ -13,7 +13,7 @@ const router = createBrowserRouter(routes); export default function App() { return ( - + diff --git a/enshi/src/Components/ArticleViewer/ArticleViewer.tsx b/enshi/src/Components/ArticleViewer/ArticleViewer.tsx index 9cc5024..842a672 100644 --- a/enshi/src/Components/ArticleViewer/ArticleViewer.tsx +++ b/enshi/src/Components/ArticleViewer/ArticleViewer.tsx @@ -1,13 +1,9 @@ -import * as Dialog from "@radix-ui/react-dialog"; -import { Cross2Icon } from "@radix-ui/react-icons"; import { Box, - Button, Container, Flex, - Select, Separator, - Text, + Text } from "@radix-ui/themes"; import { useQuery } from "@tanstack/react-query"; import { Interweave } from "interweave"; @@ -15,6 +11,7 @@ import { useAtomValue } from "jotai"; import { useParams } from "react-router-dom"; import { axiosLocalhost } from "../../api/axios/axios"; import { userAtom } from "../../AtomStore/AtomStore"; +import AddPostToBlogDialog from "../Dialogs/AddPostToBlogDialog/AddPostToBlogDialog"; import ChangePostButton from "./ChangePostButton/ChangePostButton"; import SkeletonPostLoader from "./SkeletonLoader/SkeletonLoader"; import VoteButton, { DOWNVOTE, UPVOTE } from "./VoteButton/VoteButton"; @@ -78,62 +75,7 @@ export default function ArticleViewer(props: TArticleViewer) { /> - - - - - - - - - Add this post to blog - - - - - {`Add "${data.title}" to blog...`} - - - - - - - This - - - This is - updated blog - - - This another - - - - - - - -
- - - -
- - - -
-
-
+ diff --git a/enshi/src/Components/Dialogs/AddPostToBlogDialog/AddPostToBlogDialog.tsx b/enshi/src/Components/Dialogs/AddPostToBlogDialog/AddPostToBlogDialog.tsx new file mode 100644 index 0000000..04deee3 --- /dev/null +++ b/enshi/src/Components/Dialogs/AddPostToBlogDialog/AddPostToBlogDialog.tsx @@ -0,0 +1,82 @@ +import * as Dialog from "@radix-ui/react-dialog"; +import { Cross2Icon } from "@radix-ui/react-icons"; +import { Button, Card, Flex, Select, Text, Theme } from "@radix-ui/themes"; +import { useQuery } from "@tanstack/react-query"; +import { useState } from "react"; +import { Blog } from "../../../@types/BlogTypes"; +import { axiosLocalhost } from "../../../api/axios/axios"; +import { JSONWithInt64 } from "../../../utils/idnex"; + +export default function AddPostToBlogDialog() { + const { data } = useQuery({ + queryKey: ["userBlogs"], + queryFn: async () => { + const response = await axiosLocalhost.get("/user/blogs", { + transformResponse: [(data) => data], + }); + + let temp = JSONWithInt64(response.data); + + return temp as Blog[]; + }, + }); + + const [selectedBlog, setSelectedBlog] = useState(""); + + return ( + + + + + + + + + + + Add this post to blog + + + + {`Add post to `} + + + + + {data?.map((blog, i) => { + return ( + + {blog.title} + + ); + })} + + + + + + +
+ + + +
+ + + +
+
+
+
+
+ ); +}