Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Update admin image view (#1412)

Sean Boult3d9e65a4deb7
diff --git a/apps/admin/public/failed.jpeg b/apps/admin/public/failed.jpeg
new file mode 100644
index 00000000..63f4498c
Binary files /dev/null and b/apps/admin/public/failed.jpeg differ
diff --git a/apps/admin/src/app/dashboard/images/image-list.tsx b/apps/admin/src/app/dashboard/images/image-list.tsx
new file mode 100644
index 00000000..ef911bf4
--- /dev/null
+++ b/apps/admin/src/app/dashboard/images/image-list.tsx
@@ -0,0 +1,27 @@
+'use client';
+import { type ImageUpload } from '@repo/db/types';
+
+// million-ignore
+export const ImageList = ({ images }: { images: ImageUpload[] }) => {
+ return (
+ <div className="flex flex-row flex-wrap gap-4">
+ {images.map((image) => (
+ <a href={image.url} key={image.id} target="_blank" rel="noreferrer">
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ alt={`${image.id}`}
+ className="bg-blue-300"
+ height="auto"
+ onError={(e) => {
+ // BUG: doesnt work cause UT doesnt throw 404
+ e.currentTarget.src = '/failed.jpeg';
+ e.currentTarget.alt = 'Failed to load image';
+ }}
+ src={image.url}
+ width="300"
+ />
+ </a>
+ ))}
+ </div>
+ );
+};
diff --git a/apps/admin/src/app/dashboard/images/page.tsx b/apps/admin/src/app/dashboard/images/page.tsx
index aaf3e94e..dd9c2462 100644
--- a/apps/admin/src/app/dashboard/images/page.tsx
+++ b/apps/admin/src/app/dashboard/images/page.tsx
@@ -1,29 +1,14 @@
import { auth } from '@repo/auth/server';
import { prisma } from '@repo/db';
-import Image from 'next/image';
import { assertAdmin } from '~/utils/auth-guards';
+import { ImageList } from './image-list';
export default async function ImagesPage() {
const session = await auth();
assertAdmin(session);
const data = await getUploadedImages();
- return (
- <div className="flex flex-col gap-2">
- <div>
- {data.map((image) => (
- <Image
- alt={`${image.id}`}
- className="rounded-lg"
- height="300"
- key={image.id}
- src={image.url}
- width="300"
- />
- ))}
- </div>
- </div>
- );
+ return <ImageList images={data} />;
}
export type UploadedImages = Awaited<ReturnType<typeof getUploadedImages>>;
@@ -37,7 +22,7 @@ export async function getUploadedImages() {
return prisma.imageUpload.findMany({
take: 100,
orderBy: {
- createdAt: 'asc',
+ createdAt: 'desc',
},
});
}