From 2915893049bfcc4a11a90037019269179c03edab Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 22 Aug 2024 17:27:04 +0200 Subject: [PATCH] start user pages --- Foxnouns.Backend/Controllers/UsersController.cs | 5 ----- Foxnouns.Frontend/src/routes/+error.svelte | 2 +- Foxnouns.Frontend/src/routes/+layout.server.ts | 2 +- Foxnouns.Frontend/src/routes/+layout.svelte | 2 +- Foxnouns.Frontend/src/routes/+page.svelte | 8 ++++---- .../src/routes/@[username]/+page.server.ts | 12 ++++++++++++ .../src/routes/@[username]/+page.svelte | 10 ++++++++++ 7 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 Foxnouns.Frontend/src/routes/@[username]/+page.server.ts create mode 100644 Foxnouns.Frontend/src/routes/@[username]/+page.svelte diff --git a/Foxnouns.Backend/Controllers/UsersController.cs b/Foxnouns.Backend/Controllers/UsersController.cs index 19bb88a..d9d8ac0 100644 --- a/Foxnouns.Backend/Controllers/UsersController.cs +++ b/Foxnouns.Backend/Controllers/UsersController.cs @@ -21,11 +21,6 @@ public class UsersController( public async Task GetUserAsync(string userRef) { var user = await db.ResolveUserAsync(userRef, CurrentToken); - return await GetUserInnerAsync(user); - } - - private async Task GetUserInnerAsync(User user) - { return Ok(await userRendererService.RenderUserAsync( user, selfUser: CurrentUser, diff --git a/Foxnouns.Frontend/src/routes/+error.svelte b/Foxnouns.Frontend/src/routes/+error.svelte index 9aec269..dd827ae 100644 --- a/Foxnouns.Frontend/src/routes/+error.svelte +++ b/Foxnouns.Frontend/src/routes/+error.svelte @@ -1,4 +1,4 @@ - diff --git a/Foxnouns.Frontend/src/routes/+layout.server.ts b/Foxnouns.Frontend/src/routes/+layout.server.ts index 78f6517..a3b3a8a 100644 --- a/Foxnouns.Frontend/src/routes/+layout.server.ts +++ b/Foxnouns.Frontend/src/routes/+layout.server.ts @@ -9,5 +9,5 @@ export async function load({ fetch, locals }) { user = await request(fetch, "GET", "/users/@me"); } catch {} - return { meta, user, token: locals.token }; + return { meta, currentUser: user, token: locals.token }; } diff --git a/Foxnouns.Frontend/src/routes/+layout.svelte b/Foxnouns.Frontend/src/routes/+layout.svelte index 608c9f3..57271d1 100644 --- a/Foxnouns.Frontend/src/routes/+layout.svelte +++ b/Foxnouns.Frontend/src/routes/+layout.svelte @@ -6,5 +6,5 @@ export let data: LayoutData; - + diff --git a/Foxnouns.Frontend/src/routes/+page.svelte b/Foxnouns.Frontend/src/routes/+page.svelte index 2971086..fa8e254 100644 --- a/Foxnouns.Frontend/src/routes/+page.svelte +++ b/Foxnouns.Frontend/src/routes/+page.svelte @@ -11,10 +11,10 @@

Visit kit.svelte.dev to read the documentation

- are you logged in? {data.user !== undefined} - {#if data.user} -
hello, {data.user.username}! -
your ID: {data.user.id} + are you logged in? {data.currentUser !== undefined} + {#if data.currentUser} +
hello, {data.currentUser.username}! +
your ID: {data.currentUser.id} {/if}

diff --git a/Foxnouns.Frontend/src/routes/@[username]/+page.server.ts b/Foxnouns.Frontend/src/routes/@[username]/+page.server.ts new file mode 100644 index 0000000..a803a26 --- /dev/null +++ b/Foxnouns.Frontend/src/routes/@[username]/+page.server.ts @@ -0,0 +1,12 @@ +import { error } from "@sveltejs/kit"; +import type { User } from "$lib/api/user"; +import request from "$lib/request"; + +export const load = async ({ params, fetch }) => { + try { + const user = await request(fetch, "GET", `/users/${params.username}`); + return { user }; + } catch { + error(404, { message: "User not found" }); + } +}; diff --git a/Foxnouns.Frontend/src/routes/@[username]/+page.svelte b/Foxnouns.Frontend/src/routes/@[username]/+page.svelte new file mode 100644 index 0000000..639bb52 --- /dev/null +++ b/Foxnouns.Frontend/src/routes/@[username]/+page.svelte @@ -0,0 +1,10 @@ + + + + @{data.user.username} • pronouns.cc + + +

this is the user page for @{data.user.username}