start user pages

This commit is contained in:
sam 2024-08-22 17:27:04 +02:00
parent ef221b2c45
commit 2915893049
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
7 changed files with 29 additions and 12 deletions

View file

@ -21,11 +21,6 @@ public class UsersController(
public async Task<IActionResult> GetUserAsync(string userRef)
{
var user = await db.ResolveUserAsync(userRef, CurrentToken);
return await GetUserInnerAsync(user);
}
private async Task<IActionResult> GetUserInnerAsync(User user)
{
return Ok(await userRendererService.RenderUserAsync(
user,
selfUser: CurrentUser,

View file

@ -1,4 +1,4 @@
<script>
<script lang="ts">
import { page } from "$app/stores";
import neofox from "./neofox_confused_2048.png";
</script>

View file

@ -9,5 +9,5 @@ export async function load({ fetch, locals }) {
user = await request<User>(fetch, "GET", "/users/@me");
} catch {}
return { meta, user, token: locals.token };
return { meta, currentUser: user, token: locals.token };
}

View file

@ -6,5 +6,5 @@
export let data: LayoutData;
</script>
<Navbar user={data.user} />
<Navbar user={data.currentUser} />
<slot />

View file

@ -11,10 +11,10 @@
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
<p>
are you logged in? {data.user !== undefined}
{#if data.user}
<br />hello, {data.user.username}!
<br />your ID: {data.user.id}
are you logged in? {data.currentUser !== undefined}
{#if data.currentUser}
<br />hello, {data.currentUser.username}!
<br />your ID: {data.currentUser.id}
{/if}
</p>

View file

@ -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<User>(fetch, "GET", `/users/${params.username}`);
return { user };
} catch {
error(404, { message: "User not found" });
}
};

View file

@ -0,0 +1,10 @@
<script lang="ts">
import type { PageData } from "./$types";
export let data: PageData;
</script>
<svelte:head>
<title>@{data.user.username} • pronouns.cc</title>
</svelte:head>
<h1>this is the user page for @{data.user.username}</h1>