From fc3b4146a5da00e4e28ac9baac953ee7627acb83 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 21:34:26 +0200 Subject: [PATCH] refactor(frontend): update API client to match cleaned REST routes --- .../components/remote-user-card.tsx | 4 +-- thoughts-frontend/lib/api.ts | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/thoughts-frontend/components/remote-user-card.tsx b/thoughts-frontend/components/remote-user-card.tsx index 332b608..7556d0f 100644 --- a/thoughts-frontend/components/remote-user-card.tsx +++ b/thoughts-frontend/components/remote-user-card.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { useAuth } from "@/hooks/use-auth"; -import { followRemoteUser, RemoteActor } from "@/lib/api"; +import { followUser, RemoteActor } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { UserAvatar } from "@/components/user-avatar"; import { toast } from "sonner"; @@ -24,7 +24,7 @@ export function RemoteUserCard({ actor }: RemoteUserCardProps) { } setLoading(true); try { - await followRemoteUser(actor.handle, token); + await followUser(actor.handle, token); setFollowed(true); toast.success(`Follow request sent to ${actor.handle}`); } catch { diff --git a/thoughts-frontend/lib/api.ts b/thoughts-frontend/lib/api.ts index d2c5359..5ae3ae2 100644 --- a/thoughts-frontend/lib/api.ts +++ b/thoughts-frontend/lib/api.ts @@ -194,18 +194,18 @@ 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-list", {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); + apiFetch("/users/me/following", {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); // ── Users ───────────────────────────────────────────────────────────────── export const getUserProfile = (username: string, token: string | null) => - apiFetch(`/users/${username}/profile`, {}, UserSchema, token); + apiFetch(`/users/${username}`, {}, UserSchema, token); export const getFollowersList = (username: string, token: string | null) => - apiFetch(`/users/${username}/follower-list`, {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); + apiFetch(`/users/${username}/followers`, {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); export const getFollowingList = (username: string, token: string | null) => - apiFetch(`/users/${username}/following-list`, {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); + apiFetch(`/users/${username}/following`, {}, z.object({ total: z.number(), items: z.array(UserSchema) }), token); export const getTopFriends = (username: string, token: string | null) => apiFetch(`/users/${username}/top-friends`, {}, z.object({ topFriends: z.array(z.string()) }), token); @@ -216,22 +216,30 @@ export const followUser = (username: string, token: string) => export const unfollowUser = (username: string, token: string) => apiFetch(`/users/${username}/follow`, { method: "DELETE" }, z.null(), token); -export const lookupRemoteActor = (handle: string, token: string | null) => +export const markNotificationRead = (id: string, token: string) => apiFetch( - `/federation/lookup?handle=${encodeURIComponent(handle)}`, - {}, - RemoteActorSchema, + `/notifications/${id}`, + { method: "PATCH", body: JSON.stringify({ read: true }) }, + z.null(), token ); -export const followRemoteUser = (handle: string, token: string) => +export const markAllNotificationsRead = (token: string) => apiFetch( - `/federation/follow`, - { method: "POST", body: JSON.stringify({ handle }) }, + "/notifications", + { method: "PATCH", body: JSON.stringify({ read: true }) }, z.null(), token ); +export const lookupRemoteActor = (handle: string, token: string | null) => + apiFetch( + `/users/lookup?handle=${encodeURIComponent(handle)}`, + {}, + RemoteActorSchema, + token + ); + export const getAllUsers = (page: number = 1, pageSize: number = 20) => apiFetch( `/users?page=${page}&per_page=${pageSize}`,