misc: fix toasts
This commit is contained in:
1 parent
f51da98f38
commit
5582e49be9
3 files changed
+29
-5
No files matched your search
+9
-3
@@ -44,11 +44,17 @@ export const profileData = writable<ProfileData>(
|
|||||||
getFromStorage<ProfileData>('profileData') ?? { profiles: [], profile: -1 }
|
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) => {
|
profileData.subscribe(async (pd) => {
|
||||||
setFromStorage('profileData', pd)
|
setFromStorage('profileData', pd)
|
||||||
|
|
||||||
if (pd.profile == -1) {
|
if (pd.profile == -1 && initialInstance != pd.defaultInstance) {
|
||||||
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
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) => {
|
profile.subscribe(async (p) => {
|
||||||
if (p?.id == -1) {
|
if (p?.id == -1) {
|
||||||
instance.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
||||||
}
|
}
|
||||||
if (!p || !p.jwt) {
|
if (!p || !p.jwt) {
|
||||||
profileData.update((pd) => ({ ...pd, profile: -1 }))
|
profileData.update((pd) => ({ ...pd, profile: -1 }))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import {
|
import {
|
||||||
type Toast,
|
type Toast,
|
||||||
toasts,
|
toasts,
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
CheckCircle,
|
CheckCircle,
|
||||||
Icon,
|
Icon,
|
||||||
XMark,
|
XMark,
|
||||||
|
Check,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
@@ -47,11 +49,23 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<p class="text-sm">{toast.content}</p>
|
<p class="text-sm">{toast.content}</p>
|
||||||
</div>
|
</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
|
<button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
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 />
|
<Icon src={XMark} size="16" mini />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ export const toastColors = {
|
|||||||
|
|
||||||
export interface Toast {
|
export interface Toast {
|
||||||
id: number
|
id: number
|
||||||
title: string | undefined
|
title?: string
|
||||||
content: string
|
content: string
|
||||||
type: ToastType
|
type: ToastType
|
||||||
|
action?: () => any
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toasts = writable<Toast[]>([])
|
export const toasts = writable<Toast[]>([])
|
||||||
@@ -23,11 +24,13 @@ export function toast({
|
|||||||
content,
|
content,
|
||||||
type = 'info',
|
type = 'info',
|
||||||
duration = 5000,
|
duration = 5000,
|
||||||
|
action,
|
||||||
}: {
|
}: {
|
||||||
title?: string
|
title?: string
|
||||||
content: string
|
content: string
|
||||||
type?: ToastType
|
type?: ToastType
|
||||||
duration?: number
|
duration?: number
|
||||||
|
action?: () => any
|
||||||
}) {
|
}) {
|
||||||
let id = 0
|
let id = 0
|
||||||
|
|
||||||
@@ -41,6 +44,7 @@ export function toast({
|
|||||||
content: content,
|
content: content,
|
||||||
title: title,
|
title: title,
|
||||||
type: type,
|
type: type,
|
||||||
|
action: action,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user