Break out some utils

This commit is contained in:
Jon Staab
2024-08-06 13:10:10 -07:00
parent 0340634ecb
commit 36a920df51
11 changed files with 84 additions and 87 deletions
+21
View File
@@ -0,0 +1,21 @@
import type {ComponentType} from "svelte"
import {readable, writable} from "svelte/store"
import {randomId} from "@welshman/lib"
import {pushState} from "$app/navigation"
export const modals = new Map()
export const pushModal = (component: ComponentType, props: Record<string, any>) => {
const id = randomId()
// TODO: fix memory leak here by listening to history somehow
modals.set(id, {component, props})
pushState("", {modal: id})
return id
}
export const popModal = (id: string) => {
modals.delete(id)
history.back()
}