misc: fix toasts

This commit is contained in:
Xyphyn committed 2023-08-03 10:51:42 -07:00
1 parent f51da98f38
commit 5582e49be9
3 files changed
+29 -5

No files matched your search

+9 -3
View File
@@ -44,11 +44,17 @@ export const profileData = writable<ProfileData>(
getFromStorage<ProfileData>('profileData') ?? { profiles: [], profile: -1 }
)
// stupid hack to get dev server working
// why does this always happen to me
let initialInstance = get(profileData).defaultInstance
profileData.subscribe(async (pd) => {
setFromStorage('profileData', pd)
if (pd.profile == -1) {
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
if (pd.profile == -1 && initialInstance != pd.defaultInstance) {
initialInstance = get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL
instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
}
})
@@ -56,7 +62,7 @@ export const profile = writable<Profile | undefined>(getProfile())
profile.subscribe(async (p) => {
if (p?.id == -1) {
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
}
if (!p || !p.jwt) {
profileData.update((pd) => ({ ...pd, profile: -1 }))
+15 -1
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import Button from '$lib/components/input/Button.svelte'
import {
type Toast,
toasts,
@@ -11,6 +12,7 @@
CheckCircle,
Icon,
XMark,
Check,
} from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
@@ -47,11 +49,23 @@
{/if}
<p class="text-sm">{toast.content}</p>
</div>
<div class="ml-auto" />
{#if toast.action}
<button
on:click={() => {
toast.action?.()
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
}}
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2 m-2"
>
<Icon src={Check} size="16" mini />
</button>
{/if}
<button
on:click={() => {
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
}}
class="rounded-lg ml-auto w-max transition-colors hover:bg-slate-200 hover:dark:bg-zinc-800 p-2 m-2"
class="rounded-lg w-max transition-colors hover:bg-black/20 hover:dark:bg-white/20 p-2 m-2"
>
<Icon src={XMark} size="16" mini />
</button>
+5 -1
View File
@@ -11,9 +11,10 @@ export const toastColors = {
export interface Toast {
id: number
title: string | undefined
title?: string
content: string
type: ToastType
action?: () => any
}
export const toasts = writable<Toast[]>([])
@@ -23,11 +24,13 @@ export function toast({
content,
type = 'info',
duration = 5000,
action,
}: {
title?: string
content: string
type?: ToastType
duration?: number
action?: () => any
}) {
let id = 0
@@ -41,6 +44,7 @@ export function toast({
content: content,
title: title,
type: type,
action: action,
},
]
})