Skip to content

Commit

Permalink
Allow page deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Zokhoi committed Sep 11, 2023
1 parent d28f110 commit b4dc705
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
28 changes: 28 additions & 0 deletions framerail/src/lib/server/page/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { wellfetch } from "$lib/server/deepwell/index.ts"
import type { Optional } from "$lib/types.ts"

export async function pageDelete(
siteId: number,
pageId: Optional<number>,
slug: string,
revisionComments: Optional<string>,
): object {
const response = await wellfetch("/page", {
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
siteId,
page: pageId ?? slug,
userId: 1, // TODO: identify user session and pass the user to the API request
revisionComments,
})
})

if (!response.ok) {
throw new Error("Unable to delete page")
}

return response.json()
}
File renamed without changes.
16 changes: 15 additions & 1 deletion framerail/src/routes/[slug]/[...extra]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pageEdit } from "$lib/server/deepwell/edit.ts"
import { pageEdit } from "$lib/server/page/edit"
import { pageDelete } from "$lib/server/page/delete"

export async function POST(event) {
let data = await event.request.formData()
Expand All @@ -19,3 +20,16 @@ export async function POST(event) {

return new Response(JSON.stringify(res));
}

export async function DELETE(event) {
let data = await event.request.formData()
let slug = event.params.slug

let pageIdVal = data.get("page-id")?.toString()
let pageId = pageIdVal ? parseInt(pageIdVal) : null
let siteId = parseInt(data.get("site-id")?.toString() ?? "1")
let comments = data.get("comments")?.toString() ?? ""

let res = await pageDelete(siteId, pageId, slug, comments)
return new Response(JSON.stringify(res));
}
18 changes: 17 additions & 1 deletion framerail/src/routes/[slug]/[...extra]/page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<script lang="ts">
export let data
import { goto } from "$app/navigation"
import { goto, invalidateAll } from "$app/navigation"
async function handleDelete() {
let fdata = new FormData()
fdata.set("site-id", data.site.siteId)
fdata.set("page-id", data.page.pageId)
await fetch(`/${data.page.slug}`, {
method: "DELETE",
body: fdata,
})
invalidateAll()
}
function navigateEdit() {
goto(`/${data.page.slug}/edit`, {
Expand Down Expand Up @@ -98,6 +109,11 @@
</form>
{:else}
<div class="editor-actions">
<button
class="editor-button button-delete clickable"
on:click={handleDelete} >
UT:Delete
</button>
<button
class="editor-button button-edit clickable"
on:click={navigateEdit} >
Expand Down

0 comments on commit b4dc705

Please sign in to comment.