diff --git a/src/lib/components/Toaster.svelte b/src/lib/components/Toaster.svelte new file mode 100644 index 0000000..2055b9c --- /dev/null +++ b/src/lib/components/Toaster.svelte @@ -0,0 +1,44 @@ + + + + + +
+ {#each $toasts as { id, data } (id)} +
+

+ {data.title} +

+ {#if data.description} +
+ {data.description} +
+ {/if} +
+ {/each} +
diff --git a/src/lib/server/posts.ts b/src/lib/server/posts.ts index 1070f35..097fab5 100644 --- a/src/lib/server/posts.ts +++ b/src/lib/server/posts.ts @@ -72,13 +72,8 @@ export async function savePost(path: string, data: App.PostData, content: string return writePost(path, data, content.trim()); } -export async function deletePostCache(path?: string): Promise { - if (path === undefined) { - postCache.clear(); - return true; - } else { - return postCache.delete(path); - } +export async function deletePostCache(path: string): Promise { + return postCache.delete(path); } async function loadPosts(): Promise> { diff --git a/src/lib/stores/once.ts b/src/lib/stores/once.ts new file mode 100644 index 0000000..23bf16e --- /dev/null +++ b/src/lib/stores/once.ts @@ -0,0 +1,24 @@ +import { writable } from "svelte/store"; + +export function once(value?: T) { + const { set, update, subscribe } = writable(value); + + return { + set, + update, + subscribe, + once: () => + new Promise((resolve) => { + let initCall = true; + const unsub = subscribe((value) => { + if (initCall) { + initCall = false; + return; + } + + unsub(); + resolve(value); + }); + }) + }; +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 8db2d40..7b78dec 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -8,10 +8,11 @@ import { themeStore } from "$lib/stores/theme"; import { withIcon } from "$lib/components/actions"; - import icon from "$lib/assets/global-icon.png"; + import Toaster from "$lib/components/Toaster.svelte"; import Menu from "~icons/mdi/menu"; import Brightness from "~icons/mdi/brightness-5"; import Moon from "~icons/mdi/moon-waning-crescent"; + import icon from "$lib/assets/global-icon.png"; // TODO: light/dark theme switching @@ -89,13 +90,13 @@ > New Post -
postAction("deletepost")} - > - Delete Post Cache -
+ + + + + + + + +
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index b9b9202..167c459 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -134,7 +134,6 @@
-
diff --git a/src/routes/post/+page.server.ts b/src/routes/post/+page.server.ts index 190cd07..9ba4839 100644 --- a/src/routes/post/+page.server.ts +++ b/src/routes/post/+page.server.ts @@ -1,6 +1,6 @@ import { base } from "$app/paths"; import { error, redirect, type Actions } from "@sveltejs/kit"; -import { deletePostCache, listPosts, savePost } from "$lib/server/posts"; +import { listPosts, savePost } from "$lib/server/posts"; import { isoDateString } from "$lib/utils/date"; export const prerender = false; @@ -23,12 +23,6 @@ export const actions = { await savePost(path, data, md); throw redirect(303, `${base}/post/${path}/edit`); - }, - deletecache: async ({ locals }) => { - const session = await locals.getSession(); - if (session?.user?.role != "admin") throw error(401, "NO U"); - - await deletePostCache(); } } satisfies Actions; diff --git a/src/routes/post/[...post]/edit/+page.svelte b/src/routes/post/[...post]/edit/+page.svelte index f11d7b6..3f13f14 100644 --- a/src/routes/post/[...post]/edit/+page.svelte +++ b/src/routes/post/[...post]/edit/+page.svelte @@ -1,4 +1,5 @@ @@ -85,17 +84,44 @@
- -
-
+
+ {#if $open} +
+
+

DELETE POST

+

+ You're deleting this post, confirm with caution!
+ The post ain't coming back after this! +

+ +
+ + +
+
+ {/if} +
+ +