Fetch images client side for admin page

This commit is contained in:
DerTyp7
2025-10-09 18:03:06 +02:00
parent af90528cfc
commit 3ca3b5fdce
2 changed files with 14 additions and 48 deletions
+1 -25
View File
@@ -1,6 +1,5 @@
import ImageManager from '@/components/ImageManager';
import ImageUpload from '@/components/ImageUpload';
import { ImagesResponse, TagsResponse } from '@/interfaces/api';
import { getSession } from '@/lib/session';
import styles from '@/styles/AdminPage.module.scss';
import { redirect } from 'next/navigation';
@@ -12,33 +11,10 @@ export default async function AdminPage() {
redirect('/login');
}
const fetchImages = async () => {
const apiUrl = new URL(
'/api/images?imagesPerPage=-1}',
process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000',
);
const response = await fetch(apiUrl.toString());
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return (await response.json()) as ImagesResponse;
};
const fetchTags = async () => {
const apiUrl = new URL('/api/tags', process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000');
const response = await fetch(apiUrl.toString());
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}
return (await response.json()) as TagsResponse;
};
return (
<div className={styles.container}>
<ImageUpload />
<ImageManager tags={await fetchTags()} images={(await fetchImages()).images} />
<ImageManager />
</div>
);
}