feat: add error messages to user pages

This commit is contained in:
Kentai Radiquum 2025-03-20 22:02:49 +05:00
parent f2f03df1a0
commit d16e4d14d4
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
10 changed files with 285 additions and 136 deletions

View file

@ -1,43 +1,65 @@
import { CollectionsFullPage } from "#/pages/CollectionsFull";
import { fetchDataViaGet } from "#/api/utils";
import type { Metadata, ResolvingMetadata } from "next";
export const dynamic = 'force-static';
export const dynamic = "force-static";
export async function generateMetadata(
{ params },
parent: ResolvingMetadata
): Promise<Metadata> {
const id: string = params.id;
const profile: any = await fetchDataViaGet(
const { data, error } = await fetchDataViaGet(
`https://api.anixart.tv/profile/${id}`
);
const previousOG = (await parent).openGraph;
if (error) {
return {
title: "Ошибка",
description: "Ошибка",
};
};
return {
title: "Коллекции - " + profile.profile.login,
description: profile.profile.status,
title: "Коллекции Пользователя - " + data.profile.login,
description: "Коллекции Пользователя - " + data.profile.login,
openGraph: {
...previousOG,
images: [
{
url: profile.profile.avatar, // Must be an absolute URL
url: data.profile.avatar, // Must be an absolute URL
width: 600,
height: 600,
},
],
},
};
}
};
export default async function Collections({ params }) {
const profile: any = await fetchDataViaGet(
const { data, error } = await fetchDataViaGet(
`https://api.anixart.tv/profile/${params.id}`
);
if (error) {
return (
<main className="flex items-center justify-center min-h-screen">
<div className="flex flex-col gap-2">
<h1 className="text-2xl font-bold">Ошибка</h1>
<p className="text-lg">
Произошла ошибка при загрузке коллекций пользователя. Попробуйте
обновить страницу или зайдите позже.
</p>
</div>
</main>
);
}
return (
<CollectionsFullPage
type="profile"
title={`Коллекции пользователя ${profile.profile.login}`}
title={`Коллекции пользователя: ${data.profile.login}`}
profile_id={params.id}
/>
);
}
};