Skip to content

Commit 2bb7c6c

Browse files
use image id for key & use unique images in seed
1 parent 29cd362 commit 2bb7c6c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/routes/users+/$username_+/notes.$noteId.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function loader({ params }: Route.LoaderArgs) {
3232
updatedAt: true,
3333
images: {
3434
select: {
35+
id: true,
3536
altText: true,
3637
objectKey: true,
3738
},
@@ -123,7 +124,7 @@ export default function NoteRoute({
123124
<div className={`${displayBar ? 'pb-24' : 'pb-12'} overflow-y-auto`}>
124125
<ul className="flex flex-wrap gap-5 py-5">
125126
{loaderData.note.images.map((image) => (
126-
<li key={image.objectKey}>
127+
<li key={image.id}>
127128
<a href={getNoteImgSrc(image.objectKey)}>
128129
<Img
129130
src={getNoteImgSrc(image.objectKey)}

prisma/seed.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ async function seed() {
5454

5555
// Add images to note
5656
const noteImageCount = faker.number.int({ min: 1, max: 3 })
57-
for (let imageIndex = 0; imageIndex < noteImageCount; imageIndex++) {
58-
const imgNumber = faker.number.int({ min: 0, max: 9 })
59-
const noteImage = noteImages[imgNumber]
60-
if (noteImage) {
61-
await prisma.noteImage.create({
57+
const selectedImages = faker.helpers.arrayElements(
58+
noteImages,
59+
noteImageCount,
60+
)
61+
await Promise.all(
62+
selectedImages.map((noteImage) =>
63+
prisma.noteImage.create({
6264
data: {
6365
noteId: note.id,
6466
altText: noteImage.altText,
6567
objectKey: noteImage.objectKey,
6668
},
67-
})
68-
}
69-
}
69+
}),
70+
),
71+
)
7072
}
7173
}
7274
console.timeEnd(`👤 Created ${totalUsers} users...`)

0 commit comments

Comments
 (0)