From e80e59350fb8b722941f4ec94892f771707c32a9 Mon Sep 17 00:00:00 2001 From: ari melody Date: Sun, 7 Jul 2024 12:57:04 +0100 Subject: [PATCH] add delete post button (#7) --- src/img/icons/bin.svg | 17 ++++++++++++++++ src/lib/api.js | 11 ++++++----- src/lib/ui/post/ActionBar.svelte | 34 +++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/img/icons/bin.svg diff --git a/src/img/icons/bin.svg b/src/img/icons/bin.svg new file mode 100644 index 0000000..9f999a7 --- /dev/null +++ b/src/img/icons/bin.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/lib/api.js b/src/lib/api.js index 9cbf898..55b520b 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -231,7 +231,7 @@ export async function createPost(host, token, post_data) { body: formdata }) - return await data.json() + return await data.json(); } /** @@ -249,16 +249,17 @@ export async function editPost(host, token, post_id, post_data) { let url = `https://${host}/api/v1/statuses/${post_id}`; const data = await fetch(url, { - method: 'POST', + method: 'PUT', headers: { "Authorization": `Bearer ${token}` }, body: formdata }) - return await data.json() + return await data.json(); } /** * DELETE /api/v1/statuses/{post_id} + * Returns the deleted post's data, in the case of republishing. * @param {string} host - The domain of the target server. * @param {string} token - The application token * @param {any} post_id - The ID of the post to delete. @@ -266,11 +267,11 @@ export async function editPost(host, token, post_id, post_data) { export async function deletePost(host, token, post_id) { let url = `https://${host}/api/v1/statuses/${post_id}`; const data = await fetch(url, { - method: 'POST', + method: 'DELETE', headers: { "Authorization": `Bearer ${token}` }, }) - return await data.json() + return await data.json(); } /** diff --git a/src/lib/ui/post/ActionBar.svelte b/src/lib/ui/post/ActionBar.svelte index 8f3e490..2a08795 100644 --- a/src/lib/ui/post/ActionBar.svelte +++ b/src/lib/ui/post/ActionBar.svelte @@ -1,9 +1,11 @@ -
+