feat: Show info of currently signed in user
This commit is contained in:
parent
fc4f482529
commit
68ea056a3b
@ -32,7 +32,8 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value={$form.channelName}
|
bind:value={$form.channelName}
|
||||||
aria-invalid={$errors.channelName ? 'true' : undefined}
|
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}
|
{#if $errors.channelName}<Label for="channelName" class="m-0 p-0 text-red-500">{$errors.channelName}</Label>{/if}
|
||||||
<Dialog.Footer>
|
<Dialog.Footer>
|
||||||
<Button type="submit">Create</Button>
|
<Button type="submit">Create</Button>
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import MessagesSquare from 'lucide-svelte/icons/messages-square';
|
import MessagesSquare from 'lucide-svelte/icons/messages-square';
|
||||||
import type { Snippet } from 'svelte';
|
import type { Snippet } from 'svelte';
|
||||||
import type { SuperValidated } from 'sveltekit-superforms';
|
import type { PageData } from '../../routes/$types';
|
||||||
import Channel from './channel.svelte';
|
import Channel from './channel.svelte';
|
||||||
import ChannelDialog from './channelDialog.svelte';
|
import ChannelDialog from './channelDialog.svelte';
|
||||||
import ModeSwitcher from './modeSwitcher.svelte';
|
import ModeSwitcher from './modeSwitcher.svelte';
|
||||||
|
import User from './user.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: SuperValidated<{
|
data: PageData;
|
||||||
channelName: string;
|
|
||||||
}>;
|
|
||||||
channels: string[];
|
|
||||||
children: Snippet;
|
children: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sidebarWidth = $state(0);
|
let sidebarWidth = $state(0);
|
||||||
const { data, channels, children }: Props = $props();
|
const { data, children }: Props = $props();
|
||||||
|
const channels = data.channels;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-screen">
|
<div class="w-screen">
|
||||||
@ -37,7 +36,8 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-auto p-4">
|
<div class="mt-auto p-4">
|
||||||
<ChannelDialog {data} />
|
<User {data} />
|
||||||
|
<ChannelDialog data={data.form} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
20
src/lib/components/user.svelte
Normal file
20
src/lib/components/user.svelte
Normal 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}
|
@ -1,9 +1,10 @@
|
|||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
|
import { auth } from '$lib/server/db/auth';
|
||||||
import { newChannelSchema } from '$lib/types/schema';
|
import { newChannelSchema } from '$lib/types/schema';
|
||||||
import { superValidate } from 'sveltekit-superforms';
|
import { superValidate } from 'sveltekit-superforms';
|
||||||
import { zod } from 'sveltekit-superforms/adapters';
|
import { zod } from 'sveltekit-superforms/adapters';
|
||||||
|
|
||||||
export async function load() {
|
export async function load({ request }) {
|
||||||
const form = await superValidate(zod(newChannelSchema));
|
const form = await superValidate(zod(newChannelSchema));
|
||||||
const rows = await db.getChannels();
|
const rows = await db.getChannels();
|
||||||
const channels: string[] = rows
|
const channels: string[] = rows
|
||||||
@ -12,7 +13,12 @@ export async function load() {
|
|||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const session = await auth.api.getSession({
|
||||||
|
headers: request.headers,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
session,
|
||||||
channels,
|
channels,
|
||||||
form,
|
form,
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModeWatcher />
|
<ModeWatcher />
|
||||||
<MainLayout data={data.form} channels={data.channels}>
|
<MainLayout {data}>
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</MainLayout>
|
</MainLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user