feat: Basic homepage

This commit is contained in:
Roman Godmaire 2023-11-19 12:43:41 -05:00
parent d68be16688
commit bb93de3074
4 changed files with 44 additions and 4 deletions

View file

@ -1,3 +1,5 @@
export interface Database {
listTracksWithProducer: (producerId: string) => Promise<{ title: string }[]>;
listTracksWithProducer: (
producerId: string
) => Promise<{ title: string; producer: { username: string } }[]>;
}

View file

@ -11,7 +11,12 @@ export class DatabasePrisma implements Database {
listTracksWithProducer = async (producerId: string) => {
const tracks = await this.client.track.findMany({
select: {
title: true
title: true,
producer: {
select: {
username: true
}
}
},
where: {
producerId

View file

@ -0,0 +1,10 @@
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ locals: { authReq, database } }) => {
const session = await authReq.validate();
const tracks = await database.listTracksWithProducer(session.user.userId);
return {
tracks
};
};

View file

@ -1,5 +1,28 @@
<script lang="ts">
export let data;
</script>
<svelte:head>
<title>Larsen</title>
</svelte:head>
{#if data.isLoggedIn}
<h1>Your Tracks</h1>
{#if data.tracks.length === 0}
No tracks!
{/if}
{#each data.tracks as track}
<article>
<hgroup>
<h1>{track.title}</h1>
<h2>by {track.producer.username}</h2>
</hgroup>
This is a track
</article>
{/each}
{:else}
Oh no.
{/if}