fix(frontend): tag remaining GET fetches for cache invalidation

This commit is contained in:
2026-05-15 19:41:50 +02:00
parent 091c3a4706
commit ed789c6170

View File

@@ -215,7 +215,7 @@ export const updateProfile = (data: z.infer<typeof UpdateProfileSchema>, token:
apiFetch("/users/me", { method: "PATCH", body: JSON.stringify(data) }, UserSchema, token); apiFetch("/users/me", { method: "PATCH", body: JSON.stringify(data) }, UserSchema, token);
export const getMeFollowingList = (token: string) => 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 ───────────────────────────────────────────────────────────────── // ── Users ─────────────────────────────────────────────────────────────────
@@ -261,7 +261,7 @@ export const markAllNotificationsRead = (token: string) =>
export const lookupRemoteActor = (handle: string, token: string | null) => export const lookupRemoteActor = (handle: string, token: string | null) =>
apiFetch( apiFetch(
`/users/lookup?handle=${encodeURIComponent(handle)}`, `/users/lookup?handle=${encodeURIComponent(handle)}`,
{}, { next: { tags: [`remote-actor:${handle}`] } },
RemoteActorSchema, RemoteActorSchema,
token token
); );
@@ -273,7 +273,7 @@ export const getRemoteActorPosts = (
) => ) =>
apiFetch( apiFetch(
`/federation/actors/${encodeURIComponent(handle)}/posts?page=${page}&per_page=20`, `/federation/actors/${encodeURIComponent(handle)}/posts?page=${page}&per_page=20`,
{}, { next: { tags: [`remote-actor:${handle}`] } },
z.object({ z.object({
total: z.number(), total: z.number(),
page: z.number(), page: z.number(),
@@ -304,7 +304,7 @@ export const getActorFollowers = (
) => ) =>
apiFetch( apiFetch(
`/federation/actors/${encodeURIComponent(handle)}/followers-list?page=${page}`, `/federation/actors/${encodeURIComponent(handle)}/followers-list?page=${page}`,
{}, { next: { tags: [`remote-actor:${handle}`] } },
ActorConnectionPageSchema, ActorConnectionPageSchema,
token token
); );
@@ -316,7 +316,7 @@ export const getActorFollowing = (
) => ) =>
apiFetch( apiFetch(
`/federation/actors/${encodeURIComponent(handle)}/following-list?page=${page}`, `/federation/actors/${encodeURIComponent(handle)}/following-list?page=${page}`,
{}, { next: { tags: [`remote-actor:${handle}`] } },
ActorConnectionPageSchema, ActorConnectionPageSchema,
token token
); );
@@ -324,13 +324,13 @@ export const getActorFollowing = (
export const getAllUsers = (page: number = 1, pageSize: number = 20) => export const getAllUsers = (page: number = 1, pageSize: number = 20) =>
apiFetch( apiFetch(
`/users?page=${page}&per_page=${pageSize}`, `/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() }) 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) })) .transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.per_page) }))
); );
export const getAllUsersCount = () => export const getAllUsersCount = () =>
apiFetch("/users/count", {}, z.object({ count: z.number() })); apiFetch("/users/count", { next: { tags: ['users'] } }, z.object({ count: z.number() }));
// ── Thoughts ────────────────────────────────────────────────────────────── // ── Thoughts ──────────────────────────────────────────────────────────────
@@ -361,7 +361,7 @@ export const getThoughtById = (thoughtId: string, token: string | null) =>
apiFetch(`/thoughts/${thoughtId}`, { next: { tags: [`thought:${thoughtId}`] } }, ThoughtSchema, token); apiFetch(`/thoughts/${thoughtId}`, { next: { tags: [`thought:${thoughtId}`] } }, ThoughtSchema, token);
export const getThoughtThread = async (thoughtId: string, token: string | null): Promise<ThoughtThread> => { export const getThoughtThread = async (thoughtId: string, token: string | null): Promise<ThoughtThread> => {
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<typeof ThoughtSchema>; type T = z.infer<typeof ThoughtSchema>;
const repliesMap: Record<string, T[]> = {}; const repliesMap: Record<string, T[]> = {};
for (const t of thoughts) { for (const t of thoughts) {
@@ -390,7 +390,7 @@ export const getThoughtsByTag = (tagName: string, token: string | null) =>
export const getPopularTags = () => export const getPopularTags = () =>
apiFetch( apiFetch(
"/tags/popular", "/tags/popular",
{}, { next: { tags: ['tags:popular'] } },
z.object({ tags: z.array(z.object({ name: z.string(), thought_count: z.number() })) }) z.object({ tags: z.array(z.object({ name: z.string(), thought_count: z.number() })) })
.transform((d) => d.tags.map((t) => t.name)) .transform((d) => d.tags.map((t) => t.name))
); );
@@ -403,7 +403,7 @@ export const search = (query: string, token: string | null) =>
// ── API Keys ────────────────────────────────────────────────────────────── // ── API Keys ──────────────────────────────────────────────────────────────
export const getApiKeys = (token: string) => 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<typeof CreateApiKeySchema>, token: string) => export const createApiKey = (data: z.infer<typeof CreateApiKeySchema>, token: string) =>
apiFetch("/api-keys", { method: "POST", body: JSON.stringify(data) }, ApiKeyResponseSchema, token); 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) => export const getPendingFollowRequests = (token: string) =>
apiFetch( apiFetch(
"/federation/me/followers/pending", "/federation/me/followers/pending",
{}, { next: { tags: ['federation:pending'] } },
z.array(RemoteActorSchema), z.array(RemoteActorSchema),
token token
); );
@@ -445,7 +445,7 @@ export const rejectFollowRequest = (actorUrl: string, token: string) =>
export const getRemoteFollowers = (token: string) => export const getRemoteFollowers = (token: string) =>
apiFetch( apiFetch(
"/federation/me/followers", "/federation/me/followers",
{}, { next: { tags: ['federation:followers'] } },
z.array(RemoteActorSchema), z.array(RemoteActorSchema),
token token
); );
@@ -453,7 +453,7 @@ export const getRemoteFollowers = (token: string) =>
export const getRemoteFollowing = (token: string) => export const getRemoteFollowing = (token: string) =>
apiFetch( apiFetch(
"/federation/me/following", "/federation/me/following",
{}, { next: { tags: ['federation:following'] } },
z.array(RemoteActorSchema), z.array(RemoteActorSchema),
token token
); );