refactor(frontend): update API client to match cleaned REST routes
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -194,18 +194,18 @@ export const updateProfile = (data: z.infer<typeof UpdateProfileSchema>, 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}`,
|
||||
|
||||
Reference in New Issue
Block a user