feat: show comments on track page

This commit is contained in:
Roman Godmaire 2023-11-25 16:16:15 -05:00
parent 4fc158119e
commit 9e4757703c
3 changed files with 52 additions and 0 deletions

View file

@ -22,6 +22,15 @@ export interface Database {
producer: { producer: {
username: string; username: string;
}; };
versions: {
comments: {
createdAt: Date;
content: string;
author: {
username: string;
};
}[];
}[];
} | null>; } | null>;
createTrack: (producerId: string, title: string, objectKey: string) => Promise<Track>; createTrack: (producerId: string, title: string, objectKey: string) => Promise<Track>;
createTrackVersion: (trackId: number) => Promise<TrackVersion>; createTrackVersion: (trackId: number) => Promise<TrackVersion>;

View file

@ -75,6 +75,24 @@ export class DatabasePrisma implements Database {
select: { select: {
username: true username: true
} }
},
versions: {
orderBy: {
id: 'desc'
},
select: {
comments: {
select: {
content: true,
createdAt: true,
author: {
select: {
username: true
}
}
}
}
}
} }
}, },
where: { where: {

View file

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import Comment from '$lib/components/Comment.svelte';
export let data; export let data;
let { track } = data; let { track } = data;
</script> </script>
@ -11,3 +12,27 @@
<h1>{track.title}</h1> <h1>{track.title}</h1>
<h2>by {track.producer.username}</h2> <h2>by {track.producer.username}</h2>
</hgroup> </hgroup>
<section>
<h2>Comments</h2>
{#each track.versions as version, versionIndex}
<!-- Automatically open the latest version's comments -->
<details open={versionIndex + 1 === track.versions.length}>
<summary>Version {versionIndex + 1}</summary>
{#each version.comments as comment, commentIndex}
<Comment
content={comment.content}
author={comment.author.username}
createdAt={comment.createdAt}
/>
<!-- Do not print the line on the last comment -->
{#if commentIndex + 1 !== version.comments.length}
<hr />
{/if}
{/each}
</details>
{/each}
</section>