diff --git a/src/app/components/PrimaryNav.svelte b/src/app/components/PrimaryNav.svelte index ca66147..0a3fe38 100644 --- a/src/app/components/PrimaryNav.svelte +++ b/src/app/components/PrimaryNav.svelte @@ -6,9 +6,9 @@
diff --git a/src/app/components/SecondaryNav.svelte b/src/app/components/SecondaryNav.svelte index 4e2768b..ea87305 100644 --- a/src/app/components/SecondaryNav.svelte +++ b/src/app/components/SecondaryNav.svelte @@ -1,6 +1,6 @@
diff --git a/src/app/modal.ts b/src/app/modal.ts new file mode 100644 index 0000000..a72dbc1 --- /dev/null +++ b/src/app/modal.ts @@ -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) => { + 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() +} diff --git a/src/app/state.ts b/src/app/state.ts index cd1002a..e905f3d 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -1,62 +1,4 @@ -import type {ComponentType} from "svelte" -import {readable, writable} from "svelte/store" -import type {FlyParams} from "svelte/transition" -import {fly as baseFly} from "svelte/transition" -import {randomId} from "@welshman/lib" -import {pushState} from "$app/navigation" - -// Animations - -export const fly = (node: Element, params?: FlyParams | undefined) => - baseFly(node, {y: 20, ...params}) - -// Toast - -export type Toast = { - id: number - message: string - options: ToastOptions -} - -export type ToastOptions = { - timeout?: number -} - -export const toast = writable(null) - -export const pushToast = ( - {message = "", id = Math.random()}: Partial, - options: ToastOptions, -) => { - toast.set({id, message, options}) - - setTimeout(() => popToast(id), options.timeout || 5000) - - return id -} - -export const popToast = (id: number) => toast.update($t => ($t?.id === id ? null : $t)) - -// Modals - -export const modals = new Map() - -export const pushModal = (component: ComponentType, props: Record) => { - 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() -} - -// App state +import {readable} from "svelte/store" export const spaces = readable([ { diff --git a/src/app/toast.ts b/src/app/toast.ts new file mode 100644 index 0000000..4d555f8 --- /dev/null +++ b/src/app/toast.ts @@ -0,0 +1,27 @@ +import {writable} from "svelte/store" +import {randomId} from "@welshman/lib" + +export type Toast = { + id: string + message: string + options: ToastOptions +} + +export type ToastOptions = { + timeout?: number +} + +export const toast = writable(null) + +export const pushToast = ( + {message = "", id = randomId()}: Partial, + options: ToastOptions, +) => { + toast.set({id, message, options}) + + setTimeout(() => popToast(id), options.timeout || 5000) + + return id +} + +export const popToast = (id: string) => toast.update($t => ($t?.id === id ? null : $t)) diff --git a/src/lib/components/Icon.svelte b/src/lib/components/Icon.svelte index aafb7f7..b3df4ba 100644 --- a/src/lib/components/Icon.svelte +++ b/src/lib/components/Icon.svelte @@ -8,18 +8,18 @@
diff --git a/svelte.config.js b/svelte.config.js index 6695d41..7324633 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -14,10 +14,10 @@ const config = { // See https://kit.svelte.dev/docs/adapters for more information about adapters. adapter: adapter(), alias: { - src: "src", - app: "src/app", - lib: "src/lib", - assets: "src/assets", + '@src': "src", + '@app': "src/app", + '@lib': "src/lib", + '@assets': "src/assets", }, }, }