diff --git a/enjoy/src/renderer/components/posts/posts.tsx b/enjoy/src/renderer/components/posts/posts.tsx index fed473a1..8ef6f9f6 100644 --- a/enjoy/src/renderer/components/posts/posts.tsx +++ b/enjoy/src/renderer/components/posts/posts.tsx @@ -1,13 +1,14 @@ import { useContext, useEffect, useState } from "react"; import { AppSettingsProviderContext } from "@renderer/context"; import { PostCard, LoaderSpin } from "@renderer/components"; -import { useToast } from "@renderer/components//ui"; +import { useToast, Button } from "@renderer/components//ui"; import { t } from "i18next"; export const Posts = () => { const { webApi } = useContext(AppSettingsProviderContext); const [loading, setLoading] = useState(true); const [posts, setPosts] = useState([]); + const [nextPage, setNextPage] = useState(1); const { toast } = useToast(); const handleDelete = (id: string) => { @@ -28,11 +29,17 @@ export const Posts = () => { }); }; - const fetchPosts = async () => { + const fetchPosts = async (page: number = nextPage) => { + if (!page) return; + webApi - .posts() + .posts({ + page, + items: 10, + }) .then((res) => { - setPosts(res.posts); + setPosts([...posts, ...res.posts]); + setNextPage(res.next); }) .catch((err) => { toast({ @@ -64,6 +71,14 @@ export const Posts = () => { ))} + + {nextPage && ( +
+ +
+ )} ); };