feat: Basic track page
This commit is contained in:
parent
eb26d1743e
commit
a9d94d73fa
5 changed files with 60 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
export let producerUsername: string;
|
export let producerUsername: string;
|
||||||
export let comments: { author: string; content: string; createdAt: Date }[];
|
export let comments: { author: string; content: string; createdAt: Date }[];
|
||||||
|
|
||||||
|
// TODO: Relative formatting (ie. 6 days ago, 3 moonths ago)
|
||||||
const formatDateTime = (datetime: Date) => {
|
const formatDateTime = (datetime: Date) => {
|
||||||
/*
|
/*
|
||||||
If the date is today, then return LocaleTimeString
|
If the date is today, then return LocaleTimeString
|
||||||
|
|
|
@ -15,6 +15,16 @@ export interface Database {
|
||||||
}[]
|
}[]
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
getTrackById: (trackId: number) => Promise<
|
||||||
|
{
|
||||||
|
title: string;
|
||||||
|
objectKey: string;
|
||||||
|
createdAt: Date;
|
||||||
|
producer: {
|
||||||
|
username: string;
|
||||||
|
};
|
||||||
|
}?
|
||||||
|
>;
|
||||||
createTrack: (producerId: string, title: string, objectKey: string) => Promise<Track>;
|
createTrack: (producerId: string, title: string, objectKey: string) => Promise<Track>;
|
||||||
insertTrackVersion: (trackId: number) => Promise<TrackVersion>;
|
insertTrackVersion: (trackId: number) => Promise<TrackVersion>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,26 @@ export class DatabasePrisma implements Database {
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getTrackById = async (trackId: number) => {
|
||||||
|
const track = await this.client.track.findUnique({
|
||||||
|
select: {
|
||||||
|
title: true,
|
||||||
|
objectKey: true,
|
||||||
|
createdAt: true,
|
||||||
|
producer: {
|
||||||
|
select: {
|
||||||
|
username: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: trackId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return track;
|
||||||
|
};
|
||||||
|
|
||||||
createTrack = async (producerId: string, title: string, objectKey: string) => {
|
createTrack = async (producerId: string, title: string, objectKey: string) => {
|
||||||
const track = await this.client.track.create({
|
const track = await this.client.track.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
20
src/routes/track/[slug]/+page.server.ts
Normal file
20
src/routes/track/[slug]/+page.server.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async ({ params: { slug }, locals: { database } }) => {
|
||||||
|
const trackId = parseInt(slug);
|
||||||
|
|
||||||
|
if (isNaN(trackId)) {
|
||||||
|
throw error(404, 'Track not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
let track = await database.getTrackById(trackId);
|
||||||
|
|
||||||
|
if (!track) {
|
||||||
|
throw error(440, 'Track not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
track
|
||||||
|
};
|
||||||
|
};
|
9
src/routes/track/[slug]/+page.svelte
Normal file
9
src/routes/track/[slug]/+page.svelte
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<script lang="ts">
|
||||||
|
export let data;
|
||||||
|
let { track } = data;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<hgroup>
|
||||||
|
<h1>{track.title}</h1>
|
||||||
|
<h2>by {track.producer.username}</h2>
|
||||||
|
</hgroup>
|
Loading…
Reference in a new issue