This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import * as Avatar from '$lib/vgui/components/ui/avatar'; | ||
import { Button } from '$lib/vgui/components/ui/button'; | ||
import type { UserResponse } from '@supabase/supabase-js'; | ||
let clazz = ''; | ||
export { clazz as class }; | ||
const getUserProfile = (userId: string) => { | ||
return $page.data.supabase.from('profiles').select('*').eq('id', userId).single(); | ||
}; | ||
const userFunc = $page.data.supabase.auth | ||
.getUser() | ||
.then((resp: UserResponse) => { | ||
if (resp.error) { | ||
throw resp.error; | ||
} | ||
return getUserProfile(resp.data.user.id); | ||
}) | ||
.then((profile: ReturnType<typeof getUserProfile>) => { | ||
if (profile.error) { | ||
throw profile.error; | ||
} | ||
return profile.data; | ||
}); | ||
</script> | ||
|
||
{#await userFunc} | ||
<Button variant="outline" class={clazz} disabled>Loading...</Button> | ||
{:then user} | ||
<Button variant="outline" class={clazz}> | ||
<Avatar.Root class="-ml-1 mr-2 h-6 w-6 rounded-full"> | ||
<Avatar.Image src={user.avatar_url} alt={user.nickname} /> | ||
<Avatar.Fallback>{user.nickname.slice(0, 1)}</Avatar.Fallback> | ||
</Avatar.Root> | ||
{user.nickname} | ||
</Button> | ||
{:catch error} | ||
<Button variant="outline" class={clazz} href="/auth">Login</Button> | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import { Avatar as AvatarPrimitive } from 'bits-ui'; | ||
import { cn } from '$lib/vgui/utils'; | ||
type $$Props = AvatarPrimitive.FallbackProps; | ||
let className: $$Props['class'] = undefined; | ||
export { className as class }; | ||
</script> | ||
|
||
<AvatarPrimitive.Fallback | ||
class={cn('flex h-full w-full items-center justify-center rounded-full bg-muted', className)} | ||
{...$$restProps} | ||
> | ||
<slot /> | ||
</AvatarPrimitive.Fallback> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script lang="ts"> | ||
import { Avatar as AvatarPrimitive } from 'bits-ui'; | ||
import { cn } from '$lib/vgui/utils'; | ||
type $$Props = AvatarPrimitive.ImageProps; | ||
let className: $$Props['class'] = undefined; | ||
export let src: $$Props['src'] = undefined; | ||
export let alt: $$Props['alt'] = undefined; | ||
export { className as class }; | ||
</script> | ||
|
||
<AvatarPrimitive.Image | ||
{src} | ||
{alt} | ||
class={cn('aspect-square h-full w-full', className)} | ||
{...$$restProps} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script lang="ts"> | ||
import { Avatar as AvatarPrimitive } from 'bits-ui'; | ||
import { cn } from '$lib/vgui/utils'; | ||
type $$Props = AvatarPrimitive.Props; | ||
let className: $$Props['class'] = undefined; | ||
export let delayMs: $$Props['delayMs'] = undefined; | ||
export { className as class }; | ||
</script> | ||
|
||
<AvatarPrimitive.Root | ||
{delayMs} | ||
class={cn('relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full', className)} | ||
{...$$restProps} | ||
> | ||
<slot /> | ||
</AvatarPrimitive.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Fallback from './avatar-fallback.svelte'; | ||
import Image from './avatar-image.svelte'; | ||
import Root from './avatar.svelte'; | ||
|
||
export { | ||
Root, | ||
Image, | ||
Fallback, | ||
// | ||
Root as Avatar, | ||
Image as AvatarImage, | ||
Fallback as AvatarFallback | ||
}; |