diff --git a/SharpbinV3.Client/src/lib/components/Navbar.svelte b/SharpbinV3.Client/src/lib/components/Navbar.svelte index 8a323d4..0cff5c6 100644 --- a/SharpbinV3.Client/src/lib/components/Navbar.svelte +++ b/SharpbinV3.Client/src/lib/components/Navbar.svelte @@ -22,7 +22,11 @@
- Sharpbin +
+ Sharpbin + Recent Pastes +
{#if $user}
{#if $user.roles.includes(1) || $user.roles.includes(255)} diff --git a/SharpbinV3.Client/src/routes/recent/+page.server.ts b/SharpbinV3.Client/src/routes/recent/+page.server.ts new file mode 100644 index 0000000..7fd694f --- /dev/null +++ b/SharpbinV3.Client/src/routes/recent/+page.server.ts @@ -0,0 +1,19 @@ +import type { PageServerLoad } from './$types'; +import type { Paste } from '$lib/types/paste'; +import { extractError } from '$lib/utils/misc'; + +export const load: PageServerLoad = async ({ fetch }) => { + try { + const res = await fetch('/api/paste/recent'); + if (!res.ok) { + const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.'; + throw new Error(errorMsg); + } + const recentPastes: Paste[] = await res.json(); + return { recentPastes }; + } + catch (error) { + console.error(error); + return { recentPastes: [] }; + } +}; diff --git a/SharpbinV3.Client/src/routes/recent/+page.svelte b/SharpbinV3.Client/src/routes/recent/+page.svelte new file mode 100644 index 0000000..2be3b40 --- /dev/null +++ b/SharpbinV3.Client/src/routes/recent/+page.svelte @@ -0,0 +1,42 @@ + + +
+
+ {#if data.recentPastes.length === 0} +

No recent pastes available.

+ {:else} +

Recent Pastes

+ + {/if} +
+