From f815d71c324aeeee3105eb2b4154161b96b8dfc1 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 28 May 2026 23:52:58 +0200 Subject: [PATCH] feat(frontend): add FeedOptions type and update getFeed to support sort/filter params --- thoughts-frontend/lib/api.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/thoughts-frontend/lib/api.ts b/thoughts-frontend/lib/api.ts index 322825b..cbacdbf 100644 --- a/thoughts-frontend/lib/api.ts +++ b/thoughts-frontend/lib/api.ts @@ -356,14 +356,36 @@ export const getAllUsersCount = () => // ── Thoughts ────────────────────────────────────────────────────────────── -export const getFeed = (token: string, page: number = 1, pageSize: number = 20) => - apiFetch( - `/feed?page=${page}&per_page=${pageSize}`, - { next: { tags: ['feed'] } }, +export type FeedSortOption = + | "newest" + | "oldest" + | "most_liked" + | "most_boosted" + | "most_discussed"; + +export type FeedOptions = { + sort?: FeedSortOption; + originals_only?: boolean; + replies_only?: boolean; + local_only?: boolean; + hide_sensitive?: boolean; +}; + +export const getFeed = (token: string, page = 1, pageSize = 20, opts: FeedOptions = {}) => { + const params = new URLSearchParams({ page: String(page), per_page: String(pageSize) }); + if (opts.sort) params.set("sort", opts.sort); + if (opts.originals_only) params.set("originals_only", "true"); + if (opts.replies_only) params.set("replies_only", "true"); + if (opts.local_only) params.set("local_only", "true"); + if (opts.hide_sensitive) params.set("hide_sensitive", "true"); + return apiFetch( + `/feed?${params.toString()}`, + { next: { tags: ["feed"] } }, z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), per_page: z.number() }) .transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.per_page) })), token ); +}; export const getUserThoughts = (username: string, token: string | null, page = 1) => apiFetch(