feat: Show info of currently signed in user

This commit is contained in:
April Hall 2025-02-09 21:04:52 -05:00
parent fc4f482529
commit 68ea056a3b
Signed by: arithefirst
GPG Key ID: 4508A15C4DB91C5B
5 changed files with 37 additions and 10 deletions

View File

@ -32,7 +32,8 @@
type="text"
bind:value={$form.channelName}
aria-invalid={$errors.channelName ? 'true' : undefined}
{...$constraints.channelName} />
{...$constraints.channelName}
/>
{#if $errors.channelName}<Label for="channelName" class="m-0 p-0 text-red-500">{$errors.channelName}</Label>{/if}
<Dialog.Footer>
<Button type="submit">Create</Button>

View File

@ -1,21 +1,20 @@
<script lang="ts">
import MessagesSquare from 'lucide-svelte/icons/messages-square';
import type { Snippet } from 'svelte';
import type { SuperValidated } from 'sveltekit-superforms';
import type { PageData } from '../../routes/$types';
import Channel from './channel.svelte';
import ChannelDialog from './channelDialog.svelte';
import ModeSwitcher from './modeSwitcher.svelte';
import User from './user.svelte';
interface Props {
data: SuperValidated<{
channelName: string;
}>;
channels: string[];
data: PageData;
children: Snippet;
}
let sidebarWidth = $state(0);
const { data, channels, children }: Props = $props();
const { data, children }: Props = $props();
const channels = data.channels;
</script>
<div class="w-screen">
@ -37,7 +36,8 @@
</nav>
</div>
<div class="mt-auto p-4">
<ChannelDialog {data} />
<User {data} />
<ChannelDialog data={data.form} />
</div>
</div>
</div>

View File

@ -0,0 +1,20 @@
<script lang="ts">
import type { PageData } from '../../routes/$types';
const { data }: { data: PageData } = $props();
const imageSrc = data.session?.user.image ?? `https://api.dicebear.com/9.x/identicon/svg?seed=${data.session?.user.name}`;
</script>
{#if data.session}
<div class="mb-1 flex w-full p-2">
<div class="avatar mr-2 rounded-sm">
<div class="h-12 w-12 overflow-hidden rounded-lg border bg-white">
<img src={imageSrc} alt="Profile image for {data.session?.user.name}" />
</div>
</div>
<div class="w-full">
<p class="font-bold">{data.session?.user.name}</p>
<p>{data.session?.user.email}</p>
</div>
</div>
{/if}

View File

@ -1,9 +1,10 @@
import { db } from '$lib/server/db';
import { auth } from '$lib/server/db/auth';
import { newChannelSchema } from '$lib/types/schema';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
export async function load() {
export async function load({ request }) {
const form = await superValidate(zod(newChannelSchema));
const rows = await db.getChannels();
const channels: string[] = rows
@ -12,7 +13,12 @@ export async function load() {
})
: [];
const session = await auth.api.getSession({
headers: request.headers,
});
return {
session,
channels,
form,
};

View File

@ -7,6 +7,6 @@
</script>
<ModeWatcher />
<MainLayout data={data.form} channels={data.channels}>
<MainLayout {data}>
{@render children()}
</MainLayout>