(initialThoughts);
+ const [page, setPage] = useState(1);
+ const [loadingMore, setLoadingMore] = useState(false);
+ const { token } = useAuth();
+
+ const thoughtThreads = buildThoughtThreads(thoughts);
+
+ const loadMore = async () => {
+ setLoadingMore(true);
+ try {
+ const result = await getUserThoughts(username, token, page + 1);
+ setThoughts((prev) => [...prev, ...result.items]);
+ setPage((p) => p + 1);
+ } catch {
+ toast.error("Failed to load more thoughts.");
+ } finally {
+ setLoadingMore(false);
+ }
+ };
+
+ if (thoughtThreads.length === 0) {
+ return (
+
+ );
+ }
+
+ return (
+
+ {thoughtThreads.map((thought) => (
+
+ ))}
+ {page < totalPages && (
+
+ )}
+
+ );
+}
diff --git a/thoughts-frontend/lib/api.ts b/thoughts-frontend/lib/api.ts
index 1b8cc59..c6b2a27 100644
--- a/thoughts-frontend/lib/api.ts
+++ b/thoughts-frontend/lib/api.ts
@@ -343,9 +343,9 @@ export const getFeed = (token: string, page: number = 1, pageSize: number = 20)
token
);
-export const getUserThoughts = (username: string, token: string | null) =>
+export const getUserThoughts = (username: string, token: string | null, page = 1) =>
apiFetch(
- `/users/${username}/thoughts`,
+ `/users/${username}/thoughts?page=${page}`,
{ next: { tags: [`profile:${username}`] } },
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), per_page: z.number() }),
token