flotilla/src/app/modal.ts

18 lines
443 B
TypeScript
Raw Normal View History

2024-08-06 20:10:10 +00:00
import type {ComponentType} from "svelte"
import {randomId} from "@welshman/lib"
2024-08-09 00:22:17 +00:00
import {goto} from "$app/navigation"
2024-08-06 20:10:10 +00:00
export const modals = new Map()
2024-08-08 21:02:46 +00:00
export const pushModal = (component: ComponentType, props: Record<string, any> = {}) => {
2024-08-06 20:10:10 +00:00
const id = randomId()
// TODO: fix memory leak here by listening to history somehow
modals.set(id, {component, props})
2024-08-09 00:22:17 +00:00
goto("#" + id)
2024-08-06 20:10:10 +00:00
return id
}
2024-08-09 00:22:17 +00:00
export const clearModal = () => goto('#')