diff --git a/enshi/src/Pages/RandomPostsPage/PostCard/PostCard.tsx b/enshi/src/Pages/RandomPostsPage/PostCard/PostCard.tsx index 2b29f64..4736527 100644 --- a/enshi/src/Pages/RandomPostsPage/PostCard/PostCard.tsx +++ b/enshi/src/Pages/RandomPostsPage/PostCard/PostCard.tsx @@ -1,17 +1,13 @@ import { ImageIcon } from "@radix-ui/react-icons"; import { Box, Card, Heading } from "@radix-ui/themes"; import { useNavigate } from "react-router-dom"; -import { GetRandomPostsRow } from "../../../@types/PostTypes"; +import { Post } from "../../../@types/PostTypes"; -type TPostCard = { - post: GetRandomPostsRow; -}; - -export default function PostCard({ post }: TPostCard) { +export default function PostCard(props: Post) { const navigate = useNavigate() const clickHandler = () => { - navigate(`/posts/${post.post_id.toString()}`) + navigate(`/posts/${props.post_id.toString()}`) } return ( @@ -22,7 +18,7 @@ export default function PostCard({ post }: TPostCard) { - {post.title} + {props.title} diff --git a/enshi/src/Pages/RandomPostsPage/RandomPostsPage.tsx b/enshi/src/Pages/RandomPostsPage/RandomPostsPage.tsx index 0d3e7f7..396d27b 100644 --- a/enshi/src/Pages/RandomPostsPage/RandomPostsPage.tsx +++ b/enshi/src/Pages/RandomPostsPage/RandomPostsPage.tsx @@ -1,10 +1,10 @@ import { Box, - Container, Flex, Heading, ScrollArea, Separator, + Text, } from "@radix-ui/themes"; import { useInfiniteQuery } from "@tanstack/react-query"; import { useEffect } from "react"; @@ -14,7 +14,7 @@ import { SelectedPostsResponse } from "../../@types/PostTypes"; import { axiosLocalhost } from "../../api/axios/axios"; import PostCard from "./PostCard/PostCard"; -const LIMIT = 3; +const LIMIT = 5; export default function RandomPostsPage() { const { t } = useTranslation(); @@ -37,33 +37,15 @@ export default function RandomPostsPage() { lastPage.next_page_index < 0 ? undefined : lastPage.next_page_index, }); - // const { data, refetch } = useQuery({ - // queryKey: ["random_posts_key"], - // queryFn: async () => { - // try { - // const response = await axiosLocalhost.get( - // `/posts/random?limit=${LIMIT}&offset=0` - // ); - - // return response.data as GetRandomPostsRow[]; - // } catch (error) { - // console.log(`Something went wrong`); - // } - - // return []; - // }, - // }); - useEffect(() => { if (inView) { - console.log(`Loading more posts...`); if (hasNextPage) fetchNextPage(); } }, [inView]); return ( <> - + {t("discover")} @@ -72,18 +54,31 @@ export default function RandomPostsPage() { {data?.pages.map((post, i) => { return ( - <> - {post.selected_posts.map((post) => { +
+ {post.selected_posts.map((post, i) => { return ( - - - +
+ +
); })} - +
); })} - qqqqqqqqqqqq + + {isFetching ? ( + Loading more... + ) : hasNextPage ? ( + fetchNextPage()} + > + Load more posts + + ) : ( + No more posts to load + )} +