refactor(frontend): update API client to match cleaned REST routes
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useAuth } from "@/hooks/use-auth";
|
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 { Button } from "@/components/ui/button";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -24,7 +24,7 @@ export function RemoteUserCard({ actor }: RemoteUserCardProps) {
|
|||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await followRemoteUser(actor.handle, token);
|
await followUser(actor.handle, token);
|
||||||
setFollowed(true);
|
setFollowed(true);
|
||||||
toast.success(`Follow request sent to ${actor.handle}`);
|
toast.success(`Follow request sent to ${actor.handle}`);
|
||||||
} catch {
|
} 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);
|
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-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 ─────────────────────────────────────────────────────────────────
|
// ── Users ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const getUserProfile = (username: string, token: string | null) =>
|
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) =>
|
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) =>
|
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) =>
|
export const getTopFriends = (username: string, token: string | null) =>
|
||||||
apiFetch(`/users/${username}/top-friends`, {}, z.object({ topFriends: z.array(z.string()) }), token);
|
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) =>
|
export const unfollowUser = (username: string, token: string) =>
|
||||||
apiFetch(`/users/${username}/follow`, { method: "DELETE" }, z.null(), token);
|
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(
|
apiFetch(
|
||||||
`/federation/lookup?handle=${encodeURIComponent(handle)}`,
|
`/notifications/${id}`,
|
||||||
{},
|
{ method: "PATCH", body: JSON.stringify({ read: true }) },
|
||||||
RemoteActorSchema,
|
z.null(),
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
|
|
||||||
export const followRemoteUser = (handle: string, token: string) =>
|
export const markAllNotificationsRead = (token: string) =>
|
||||||
apiFetch(
|
apiFetch(
|
||||||
`/federation/follow`,
|
"/notifications",
|
||||||
{ method: "POST", body: JSON.stringify({ handle }) },
|
{ method: "PATCH", body: JSON.stringify({ read: true }) },
|
||||||
z.null(),
|
z.null(),
|
||||||
token
|
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) =>
|
export const getAllUsers = (page: number = 1, pageSize: number = 20) =>
|
||||||
apiFetch(
|
apiFetch(
|
||||||
`/users?page=${page}&per_page=${pageSize}`,
|
`/users?page=${page}&per_page=${pageSize}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user