Skip to content

Commit ad9f4d0

Browse files
committed
refactor: layout level data loading and basic layout
1 parent f017381 commit ad9f4d0

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

frontend/src/lib/functions/date.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ export class FormatDate {
1919
this.parsedDate = _date;
2020
}
2121

22+
format() {
23+
const formatted_date = this.parsedDate.toLocaleDateString('en-US', {
24+
month: 'short',
25+
day: 'numeric',
26+
year: 'numeric'
27+
});
28+
return formatted_date;
29+
}
30+
2231
timeAgo() {
2332
const diff_time = Math.floor((new Date().valueOf() - this.parsedDate.valueOf()) / 1000);
2433
if (diff_time <= 0) return 'just now';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function pluralize(str: string, count: number) {
2+
return count <= 1 ? str : str + 's';
3+
}

frontend/src/routes/(app)/q/[name]/+page.server.ts renamed to frontend/src/routes/(app)/q/[name]/+layout.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import client from '$lib/clients/client';
21
import { redirect } from '@sveltejs/kit';
3-
import type { PageServerLoad } from './$types';
2+
import type { LayoutServerLoad } from './$types';
3+
import client from '$lib/clients/client';
44

5-
export const load: PageServerLoad = async ({ params }) => {
5+
export const load: LayoutServerLoad = async ({ params }) => {
66
const { data, error, response } = await client.GET('/api/v1/quiblets/{name}/', {
77
params: {
88
path: { name: params.name }
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<script lang="ts">
2-
const { children } = $props();
2+
import type { Snippet } from 'svelte';
3+
import type { PageData } from './$types';
4+
import { FormatDate } from '$lib/functions/date';
5+
import { pluralize } from '$lib/functions/pluralize';
6+
7+
const { data, children }: { data: PageData; children: Snippet } = $props();
8+
const { quiblet } = data;
39
</script>
410

511
<div class="flex h-max flex-1 flex-col gap-4 p-4">
@@ -9,6 +15,25 @@
915
<div
1016
class="fixed top-[3.75rem] flex h-[calc(100dvh-3.75rem)] w-80 flex-col gap-4 overflow-y-scroll p-4 scrollbar-none"
1117
>
12-
Hey!
18+
<div class="flex flex-col gap-2">
19+
<h3 class="font-medium">{quiblet?.title ?? `q/${quiblet?.name}`}</h3>
20+
<p class="text-sm text-base-content/75">{quiblet?.description}</p>
21+
<div class="flex items-center gap-2 text-xs">
22+
<coreicons-shape-gift class="size-4"></coreicons-shape-gift>
23+
Created {new FormatDate(quiblet?.created_at ?? '').format()}
24+
</div>
25+
<div class="flex items-center gap-2 text-xs">
26+
<coreicons-shape-globe class="size-4"></coreicons-shape-globe>
27+
{quiblet?.is_public ? 'Public' : 'Private'}
28+
</div>
29+
</div>
30+
<div class="flex items-center gap-2">
31+
<div class="flex flex-col">
32+
<span class="text-sm text-info">{quiblet?.members?.length}</span>
33+
<span class="text-xs text-base-content/75"
34+
>{pluralize('Member', quiblet?.members?.length ?? 0)}</span
35+
>
36+
</div>
37+
</div>
1338
</div>
1439
</div>

frontend/src/routes/(app)/q/[name]/+page.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,22 @@
1919
)}
2020
style="background-image: url({quiblet?.banner});"
2121
></div>
22-
<div class="absolute inset-x-0 -bottom-10 flex items-end px-4">
23-
<div class="flex items-end">
22+
<div class="absolute inset-x-0 -bottom-12 flex items-end justify-between px-4">
23+
<div class="flex items-end gap-2">
2424
<Avatar class="!size-20 outline outline-8 outline-base-300" src={quiblet?.avatar} />
25-
<h3>q/{quiblet?.name}</h3>
25+
<h3 class="text-3xl font-bold text-info">q/{quiblet?.name}</h3>
26+
</div>
27+
<div class="flex items-center gap-2">
28+
<button class="btn btn-primary h-10 px-3" aria-label="Create a Post">
29+
<coreicons-shape-plus variant="no-border" class="size-5"></coreicons-shape-plus>
30+
<span class="text-sm font-medium">Create Quib</span>
31+
</button>
32+
<button class="btn btn-secondary h-10 px-3" aria-label="Join quiblet">
33+
<span class="text-sm font-medium">Join</span>
34+
</button>
35+
<button class="btn btn-neutral size-10 p-0" aria-label="More options">
36+
<coreicons-shape-more class="size-5 rotate-90"></coreicons-shape-more>
37+
</button>
2638
</div>
2739
</div>
2840
</div>

0 commit comments

Comments
 (0)