feat: Add login stuff

This commit is contained in:
Xyphyn committed 2023-07-04 13:08:58 -07:00
1 parent f71ad4be8e
commit f0523b0c3f
18 files changed
+288 -56

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
<script lang="ts">
export let url: string
export let alt: string = ''
export let width: number
</script>
<img
src={url}
{alt}
{width}
loading="lazy"
class="rounded-full aspect-square object-cover"
/>
+35 -13
View File
@@ -1,9 +1,16 @@
<script lang="ts">
import { goto } from '$app/navigation'
import Link from '$lib/components/input/Link.svelte'
import Logo from '$lib/components/ui/Logo.svelte'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { instance_url, user } from '$lib/lemmy.js'
import {
DEFAULT_INSTANCE_URL,
authData,
instance_url,
user,
} from '$lib/lemmy.js'
import { Color } from '$lib/ui/colors.js'
import {
ArrowLeftOnRectangle,
ArrowRightOnRectangle,
@@ -21,14 +28,16 @@
<Logo width={40} />
<div class="flex flex-col">
<span class="font-bold">Xylemmy</span>
{#if $instance_url}
<span
class="text-xs opacity-50
transition-opacity"
>
{new URL(`https://${$instance_url}`).hostname}
</span>
{/if}
<span
class="text-xs opacity-50
transition-opacity"
>
{#if $authData?.instance}
{$authData.instance}
{:else}
{DEFAULT_INSTANCE_URL}
{/if}
</span>
</div>
</a>
</div>
@@ -50,9 +59,22 @@
{/if}
</button>
<span class="text-xs opacity-80 text-left mx-4 my-2">Profile</span>
<MenuButton link href="/login">
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
</MenuButton>
<MenuButton><Icon src={Cog6Tooth} mini width={16} /> Settings</MenuButton>
{#if !$user}
<MenuButton link href="/login">
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
</MenuButton>
{:else}
<MenuButton
on:click={() => {
localStorage.removeItem('user')
goto('/', {
invalidateAll: true,
})
}}
color={Color.dangerSecondary}
>
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
</MenuButton>
{/if}
</Menu>
</nav>
+57
View File
@@ -0,0 +1,57 @@
<script lang="ts">
import {
ToastType,
type Toast,
toasts,
} from '$lib/components/ui/toasts/toasts'
import {
InformationCircle,
ExclamationTriangle,
ExclamationCircle,
CheckCircle,
Icon,
XMark,
} from 'svelte-hero-icons'
import { expoInOut } from 'svelte/easing'
import { scale } from 'svelte/transition'
export let toast: Toast
</script>
<div
class="relative w-80 min-h-[4rem] dark:bg-zinc-900 bg-white shadow-lg rounded-md overflow-hidden flex flex-row items-center"
transition:scale={{
duration: 500,
start: 0.8,
easing: expoInOut,
}}
>
<div
class="h-full w-[2px] absolute left-0 top-0 bg-gradient-to-b {toast.type}"
/>
<Icon
size="20"
solid
class="relative m-2 ml-4 flex-shrink-0 {toast.type}"
src={toast.type == ToastType.info
? InformationCircle
: toast.type == ToastType.success
? CheckCircle
: toast.type == ToastType.warning
? ExclamationTriangle
: toast.type == ToastType.error
? ExclamationCircle
: ExclamationCircle}
/>
<div class="flex flex-col p-4 pl-0">
<h1 class="text-base font-bold">{toast.title}</h1>
<p class="text-sm">{toast.content}</p>
</div>
<button
on:click={() => {
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
}}
class="absolute top-0 right-0 p-2 m-2 rounded-lg transition-colors hover:bg-slate-100 hover:dark:bg-zinc-700"
>
<Icon src={XMark} size="20" />
</button>
</div>
@@ -0,0 +1,19 @@
<script lang="ts">
import Toast from '$lib/components/ui/toasts/Toast.svelte'
import { flip } from 'svelte/animate'
import { expoInOut } from 'svelte/easing'
import { toasts } from '$lib/components/ui/toasts/toasts'
</script>
<div
class="fixed right-0 top-0 flex flex-col gap-4 z-50 p-4 overflow-hidden h-screen min-w-[24rem] items-end pointer-events-none"
>
{#each $toasts as toast (toast.id)}
<div
animate:flip={{ duration: 500, easing: expoInOut }}
class="pointer-events-auto"
>
<Toast {toast} />
</div>
{/each}
</div>
+39
View File
@@ -0,0 +1,39 @@
import { writable } from 'svelte/store'
export enum ToastType {
'error' = 'from-red-400 to-red-400 text-red-400',
'warning' = 'from-yellow-300 to-yellow-300 text-yellow-300',
'success' = 'from-green-400 to-green-400 text-green-400',
'info' = '',
}
export interface Toast {
id: number
title: string
content: string
type: ToastType
}
export const toasts = writable<Toast[]>([])
export function addToast(title: string, content: string, type: ToastType) {
let id = 0
toasts.update((toasts) => {
id = Math.floor(Math.random() * 10000)
return [
{
id: id,
content: content,
title: title,
type: type,
},
...toasts,
]
})
setTimeout(() => {
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
}, 5000)
}