From ed789c617032b9b76d194958dd07cf44372eb13c Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Fri, 15 May 2026 19:41:50 +0200 Subject: [PATCH] fix(frontend): tag remaining GET fetches for cache invalidation --- thoughts-frontend/lib/api.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/thoughts-frontend/lib/api.ts b/thoughts-frontend/lib/api.ts index 075a439..d88ff8f 100644 --- a/thoughts-frontend/lib/api.ts +++ b/thoughts-frontend/lib/api.ts @@ -215,7 +215,7 @@ export const updateProfile = (data: z.infer, token: apiFetch("/users/me", { method: "PATCH", body: JSON.stringify(data) }, UserSchema, token); export const getMeFollowingList = (token: string) => - apiFetch("/users/me/following", {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); + apiFetch("/users/me/following", { next: { tags: ['me'] } }, z.object({ total: z.number(), items: z.array(UserSchema) }), token); // ── Users ───────────────────────────────────────────────────────────────── @@ -261,7 +261,7 @@ export const markAllNotificationsRead = (token: string) => export const lookupRemoteActor = (handle: string, token: string | null) => apiFetch( `/users/lookup?handle=${encodeURIComponent(handle)}`, - {}, + { next: { tags: [`remote-actor:${handle}`] } }, RemoteActorSchema, token ); @@ -273,7 +273,7 @@ export const getRemoteActorPosts = ( ) => apiFetch( `/federation/actors/${encodeURIComponent(handle)}/posts?page=${page}&per_page=20`, - {}, + { next: { tags: [`remote-actor:${handle}`] } }, z.object({ total: z.number(), page: z.number(), @@ -304,7 +304,7 @@ export const getActorFollowers = ( ) => apiFetch( `/federation/actors/${encodeURIComponent(handle)}/followers-list?page=${page}`, - {}, + { next: { tags: [`remote-actor:${handle}`] } }, ActorConnectionPageSchema, token ); @@ -316,7 +316,7 @@ export const getActorFollowing = ( ) => apiFetch( `/federation/actors/${encodeURIComponent(handle)}/following-list?page=${page}`, - {}, + { next: { tags: [`remote-actor:${handle}`] } }, ActorConnectionPageSchema, token ); @@ -324,13 +324,13 @@ export const getActorFollowing = ( export const getAllUsers = (page: number = 1, pageSize: number = 20) => apiFetch( `/users?page=${page}&per_page=${pageSize}`, - {}, + { next: { tags: ['users'] } }, z.object({ items: z.array(UserSchema), total: z.number(), page: z.number(), per_page: z.number() }) .transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.per_page) })) ); export const getAllUsersCount = () => - apiFetch("/users/count", {}, z.object({ count: z.number() })); + apiFetch("/users/count", { next: { tags: ['users'] } }, z.object({ count: z.number() })); // ── Thoughts ────────────────────────────────────────────────────────────── @@ -361,7 +361,7 @@ export const getThoughtById = (thoughtId: string, token: string | null) => apiFetch(`/thoughts/${thoughtId}`, { next: { tags: [`thought:${thoughtId}`] } }, ThoughtSchema, token); export const getThoughtThread = async (thoughtId: string, token: string | null): Promise => { - const thoughts = await apiFetch(`/thoughts/${thoughtId}/thread`, {}, z.array(ThoughtSchema), token); + const thoughts = await apiFetch(`/thoughts/${thoughtId}/thread`, { next: { tags: [`thought:${thoughtId}`] } }, z.array(ThoughtSchema), token); type T = z.infer; const repliesMap: Record = {}; for (const t of thoughts) { @@ -390,7 +390,7 @@ export const getThoughtsByTag = (tagName: string, token: string | null) => export const getPopularTags = () => apiFetch( "/tags/popular", - {}, + { next: { tags: ['tags:popular'] } }, z.object({ tags: z.array(z.object({ name: z.string(), thought_count: z.number() })) }) .transform((d) => d.tags.map((t) => t.name)) ); @@ -403,7 +403,7 @@ export const search = (query: string, token: string | null) => // ── API Keys ────────────────────────────────────────────────────────────── export const getApiKeys = (token: string) => - apiFetch("/api-keys", {}, z.object({ keys: z.array(ApiKeySchema) }), token); + apiFetch("/api-keys", { next: { tags: ['api-keys'] } }, z.object({ keys: z.array(ApiKeySchema) }), token); export const createApiKey = (data: z.infer, token: string) => apiFetch("/api-keys", { method: "POST", body: JSON.stringify(data) }, ApiKeyResponseSchema, token); @@ -421,7 +421,7 @@ export const getFriends = (token: string) => export const getPendingFollowRequests = (token: string) => apiFetch( "/federation/me/followers/pending", - {}, + { next: { tags: ['federation:pending'] } }, z.array(RemoteActorSchema), token ); @@ -445,7 +445,7 @@ export const rejectFollowRequest = (actorUrl: string, token: string) => export const getRemoteFollowers = (token: string) => apiFetch( "/federation/me/followers", - {}, + { next: { tags: ['federation:followers'] } }, z.array(RemoteActorSchema), token ); @@ -453,7 +453,7 @@ export const getRemoteFollowers = (token: string) => export const getRemoteFollowing = (token: string) => apiFetch( "/federation/me/following", - {}, + { next: { tags: ['federation:following'] } }, z.array(RemoteActorSchema), token );