fix(frontend): align Zod schemas with camelCase API responses
per_page → perPage in paginated response schemas, drop tag field from tag endpoint
This commit is contained in:
@@ -68,7 +68,7 @@ export default async function RemoteActorPage({
|
|||||||
const postsData = postsResult.status === "fulfilled" ? postsResult.value : null;
|
const postsData = postsResult.status === "fulfilled" ? postsResult.value : null;
|
||||||
const posts = postsData?.items ?? [];
|
const posts = postsData?.items ?? [];
|
||||||
const totalPages = postsData
|
const totalPages = postsData
|
||||||
? Math.ceil(postsData.total / postsData.per_page)
|
? Math.ceil(postsData.total / postsData.perPage)
|
||||||
: 1;
|
: 1;
|
||||||
const me =
|
const me =
|
||||||
meResult.status === "fulfilled" ? (meResult.value as Me | null) : null;
|
meResult.status === "fulfilled" ? (meResult.value as Me | null) : null;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export default async function ProfilePage({ params }: ProfilePageProps) {
|
|||||||
const thoughtsData = thoughtsResult.status === "fulfilled" ? thoughtsResult.value : null;
|
const thoughtsData = thoughtsResult.status === "fulfilled" ? thoughtsResult.value : null;
|
||||||
const thoughts = thoughtsData?.items ?? [];
|
const thoughts = thoughtsData?.items ?? [];
|
||||||
const totalPages = thoughtsData
|
const totalPages = thoughtsData
|
||||||
? Math.ceil(thoughtsData.total / thoughtsData.per_page)
|
? Math.ceil(thoughtsData.total / thoughtsData.perPage)
|
||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
const localFollowersCount =
|
const localFollowersCount =
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ export default async function AllUsersPage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { items, total, per_page } = usersData;
|
const { items, total, perPage } = usersData;
|
||||||
const totalPages = Math.ceil(total / per_page);
|
const totalPages = Math.ceil(total / perPage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto max-w-2xl p-4 sm:p-6">
|
<div className="container mx-auto max-w-2xl p-4 sm:p-6">
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ export const getRemoteActorPosts = (
|
|||||||
z.object({
|
z.object({
|
||||||
total: z.number(),
|
total: z.number(),
|
||||||
page: z.number(),
|
page: z.number(),
|
||||||
per_page: z.number(),
|
perPage: z.number(),
|
||||||
items: z.array(ThoughtSchema),
|
items: z.array(ThoughtSchema),
|
||||||
}),
|
}),
|
||||||
token
|
token
|
||||||
@@ -347,8 +347,8 @@ 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'] } },
|
{ 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(), perPage: z.number() })
|
||||||
.transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.per_page) }))
|
.transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.perPage) }))
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getAllUsersCount = () =>
|
export const getAllUsersCount = () =>
|
||||||
@@ -381,8 +381,8 @@ export const getFeed = (token: string, page = 1, pageSize = 20, opts: FeedOption
|
|||||||
return apiFetch(
|
return apiFetch(
|
||||||
`/feed?${params.toString()}`,
|
`/feed?${params.toString()}`,
|
||||||
{ next: { tags: ["feed"] } },
|
{ next: { tags: ["feed"] } },
|
||||||
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), per_page: z.number() })
|
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), perPage: z.number() })
|
||||||
.transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.per_page) })),
|
.transform((d) => ({ ...d, totalPages: Math.ceil(d.total / d.perPage) })),
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -391,7 +391,7 @@ export const getUserThoughts = (username: string, token: string | null, page = 1
|
|||||||
apiFetch(
|
apiFetch(
|
||||||
`/users/${username}/thoughts?page=${page}`,
|
`/users/${username}/thoughts?page=${page}`,
|
||||||
{ next: { tags: [`profile:${username}`] } },
|
{ next: { tags: [`profile:${username}`] } },
|
||||||
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), per_page: z.number() }),
|
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), perPage: z.number() }),
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ export const getThoughtsByTag = (tagName: string, token: string | null) =>
|
|||||||
apiFetch(
|
apiFetch(
|
||||||
`/tags/${tagName}`,
|
`/tags/${tagName}`,
|
||||||
{ next: { tags: [`tag:${tagName}`, 'feed'] } },
|
{ next: { tags: [`tag:${tagName}`, 'feed'] } },
|
||||||
z.object({ tag: z.string(), items: z.array(ThoughtSchema), total: z.number(), page: z.number(), per_page: z.number() }),
|
z.object({ items: z.array(ThoughtSchema), total: z.number(), page: z.number(), perPage: z.number() }),
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user