From f5ebc1748a5399aa20358272fa7e85395e0e46dc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 11 Mar 2024 23:03:07 +0800 Subject: [PATCH] :sparkles: Deletion --- .../src/components/comments/CommentList.vue | 2 +- pkg/views/src/components/posts/PostItem.vue | 13 ++++- .../src/components/publish/ArticleEditor.vue | 2 +- .../src/components/publish/CommentEditor.vue | 36 ++++++++++--- .../src/components/publish/MomentEditor.vue | 4 +- .../src/components/publish/PostAction.vue | 9 +++- .../src/components/publish/PostDeletion.vue | 51 +++++++++++++++++++ pkg/views/src/stores/editor.ts | 15 ++++-- pkg/views/src/views/posts/articles.vue | 4 +- 9 files changed, 115 insertions(+), 21 deletions(-) create mode 100644 pkg/views/src/components/publish/PostDeletion.vue diff --git a/pkg/views/src/components/comments/CommentList.vue b/pkg/views/src/components/comments/CommentList.vue index f56c2ef..a390071 100644 --- a/pkg/views/src/components/comments/CommentList.vue +++ b/pkg/views/src/components/comments/CommentList.vue @@ -3,7 +3,7 @@ -
+
diff --git a/pkg/views/src/components/posts/PostItem.vue b/pkg/views/src/components/posts/PostItem.vue index d46ab3c..4cd657d 100644 --- a/pkg/views/src/components/posts/PostItem.vue +++ b/pkg/views/src/components/posts/PostItem.vue @@ -47,7 +47,7 @@ - +
@@ -81,10 +81,19 @@ const isOwned = computed(() => props.item?.author_id === id.userinfo.data.id) function editPost() { editor.related.edit_to = props.item - if(editor.show.hasOwnProperty(props.item.model_type)) { + if (editor.show.hasOwnProperty(props.item.model_type)) { // @ts-ignore editor.show[props.item.model_type] = true } + if (props.item.model_type === "comment") { + editor.related.comment_to = props.item + } +} + +function deletePost() { + editor.related.delete_to = JSON.parse(JSON.stringify(props.item)) + editor.related.delete_to.model_type = props.item.model_type + "s" + editor.show.delete = true } function updateReactions(symbol: string, num: number) { diff --git a/pkg/views/src/components/publish/ArticleEditor.vue b/pkg/views/src/components/publish/ArticleEditor.vue index 59045f7..2dc09d7 100644 --- a/pkg/views/src/components/publish/ArticleEditor.vue +++ b/pkg/views/src/components/publish/ArticleEditor.vue @@ -21,7 +21,7 @@ - + You are editing a post with alias {{ editor.related.edit_to?.alias }} diff --git a/pkg/views/src/components/publish/CommentEditor.vue b/pkg/views/src/components/publish/CommentEditor.vue index b5289dd..e533ad6 100644 --- a/pkg/views/src/components/publish/CommentEditor.vue +++ b/pkg/views/src/components/publish/CommentEditor.vue @@ -2,7 +2,11 @@ - + + You are editing a comment with alias {{ editor.related.edit_to?.alias }} + + +

Your comment will leave below {{ postIdentifier }}

@@ -26,7 +30,7 @@ import { request } from "@/scripts/request" import { useEditor } from "@/stores/editor" import { getAtk } from "@/stores/userinfo" -import { computed, ref } from "vue" +import { computed, ref, watch } from "vue" const editor = useEditor() @@ -43,16 +47,26 @@ const error = ref(null) const success = ref(false) const loading = ref(false) +const data = ref({ + content: "" +}) + async function postComment(evt: SubmitEvent) { const form = evt.target as HTMLFormElement - const data = new FormData(form) - if (!data.has("content")) return + const payload = data.value + + if (!payload.content) return + + const url = editor.related.edit_to + ? `/api/p/comments/${editor.related.edit_to?.id}` + : `/api/p/${target.value?.model_type}/${target.value?.alias}/comments` + const method = editor.related.edit_to ? "PUT" : "POST" loading.value = true - const res = await request(`/api/p/${target.value?.model_type}/${target.value?.alias}/comments`, { - method: "POST", - headers: { Authorization: `Bearer ${getAtk()}` }, - body: data + const res = await request(url, { + method: method, + headers: { "Content-Type": "application/json", Authorization: `Bearer ${getAtk()}` }, + body: JSON.stringify(payload) }) if (res.status === 200) { form.reset() @@ -64,4 +78,10 @@ async function postComment(evt: SubmitEvent) { loading.value = false editor.done = true } + +watch(editor.related, (val) => { + if (val.edit_to && val.edit_to.model_type === "comment") { + data.value = val.edit_to + } +}) diff --git a/pkg/views/src/components/publish/MomentEditor.vue b/pkg/views/src/components/publish/MomentEditor.vue index ef97f68..89e2414 100644 --- a/pkg/views/src/components/publish/MomentEditor.vue +++ b/pkg/views/src/components/publish/MomentEditor.vue @@ -2,7 +2,7 @@ - + You are editing a post with alias {{ editor.related.edit_to?.alias }} @@ -117,7 +117,7 @@ async function postMoment(evt: SubmitEvent) { } watch(editor.related, (val) => { - if (val.edit_to) { + if (val.edit_to && val.edit_to.model_type === "moment") { data.value = val.edit_to } }) diff --git a/pkg/views/src/components/publish/PostAction.vue b/pkg/views/src/components/publish/PostAction.vue index 143feba..e2c00ea 100644 --- a/pkg/views/src/components/publish/PostAction.vue +++ b/pkg/views/src/components/publish/PostAction.vue @@ -8,13 +8,18 @@ + + + + diff --git a/pkg/views/src/components/publish/PostDeletion.vue b/pkg/views/src/components/publish/PostDeletion.vue new file mode 100644 index 0000000..65a17cb --- /dev/null +++ b/pkg/views/src/components/publish/PostDeletion.vue @@ -0,0 +1,51 @@ + + + diff --git a/pkg/views/src/stores/editor.ts b/pkg/views/src/stores/editor.ts index 06e5259..0abe001 100644 --- a/pkg/views/src/stores/editor.ts +++ b/pkg/views/src/stores/editor.ts @@ -1,5 +1,6 @@ import { defineStore } from "pinia" import { reactive, ref } from "vue" +import { getAtk } from "@/stores/userinfo" export const useEditor = defineStore("editor", () => { const done = ref(false) @@ -7,14 +8,22 @@ export const useEditor = defineStore("editor", () => { const show = reactive({ moment: false, article: false, - comment: false + comment: false, + delete: false }) - const related = reactive<{ edit_to: any; comment_to: any; reply_to: any; repost_to: any }>({ + const related = reactive<{ + edit_to: any + comment_to: any + reply_to: any + repost_to: any + delete_to: any + }>({ edit_to: null, comment_to: null, reply_to: null, - repost_to: null + repost_to: null, + delete_to: null }) return { show, related, done } diff --git a/pkg/views/src/views/posts/articles.vue b/pkg/views/src/views/posts/articles.vue index 7698cc5..d05f308 100644 --- a/pkg/views/src/views/posts/articles.vue +++ b/pkg/views/src/views/posts/articles.vue @@ -1,6 +1,6 @@