From 1f69fcbfb43b358a608719a3e3dcb89a798d2c5c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 9 Mar 2024 17:32:45 +0800 Subject: [PATCH] :sparkles: Article editor --- .../src/components/publish/ArticleEditor.vue | 152 ++++++++++++++++++ .../src/components/publish/CommentEditor.vue | 6 +- .../src/components/publish/MomentEditor.vue | 6 +- .../src/components/publish/PostAction.vue | 10 +- pkg/views/src/views/posts/details.vue | 5 +- 5 files changed, 169 insertions(+), 10 deletions(-) create mode 100644 pkg/views/src/components/publish/ArticleEditor.vue diff --git a/pkg/views/src/components/publish/ArticleEditor.vue b/pkg/views/src/components/publish/ArticleEditor.vue new file mode 100644 index 0000000..5e577ec --- /dev/null +++ b/pkg/views/src/components/publish/ArticleEditor.vue @@ -0,0 +1,152 @@ + + + + + diff --git a/pkg/views/src/components/publish/CommentEditor.vue b/pkg/views/src/components/publish/CommentEditor.vue index 563ac91..b5289dd 100644 --- a/pkg/views/src/components/publish/CommentEditor.vue +++ b/pkg/views/src/components/publish/CommentEditor.vue @@ -44,7 +44,8 @@ const success = ref(false) const loading = ref(false) async function postComment(evt: SubmitEvent) { - const data = new FormData(evt.target as HTMLFormElement) + const form = evt.target as HTMLFormElement + const data = new FormData(form) if (!data.has("content")) return loading.value = true @@ -54,12 +55,13 @@ async function postComment(evt: SubmitEvent) { body: data }) if (res.status === 200) { + form.reset() success.value = true + editor.show.comment = false } else { error.value = await res.text() } loading.value = false - editor.show.comment = false editor.done = true } diff --git a/pkg/views/src/components/publish/MomentEditor.vue b/pkg/views/src/components/publish/MomentEditor.vue index da32aa4..4e666aa 100644 --- a/pkg/views/src/components/publish/MomentEditor.vue +++ b/pkg/views/src/components/publish/MomentEditor.vue @@ -85,7 +85,8 @@ const success = ref(false) const loading = ref(false) async function postMoment(evt: SubmitEvent) { - const data = new FormData(evt.target as HTMLFormElement) + const form = evt.target as HTMLFormElement + const data = new FormData(form) if (!data.has("content")) return if (!extras.publishedAt) data.set("published_at", new Date().toISOString()) else data.set("published_at", extras.publishedAt) @@ -97,11 +98,12 @@ async function postMoment(evt: SubmitEvent) { body: data }) if (res.status === 200) { + form.reset() success.value = true + editor.show.moment = false } else { error.value = await res.text() } loading.value = false - editor.show.moment = false } diff --git a/pkg/views/src/components/publish/PostAction.vue b/pkg/views/src/components/publish/PostAction.vue index 8adf000..143feba 100644 --- a/pkg/views/src/components/publish/PostAction.vue +++ b/pkg/views/src/components/publish/PostAction.vue @@ -1,9 +1,12 @@ @@ -11,6 +14,7 @@ import { useEditor } from "@/stores/editor" import MomentEditor from "@/components/publish/MomentEditor.vue" import CommentEditor from "@/components/publish/CommentEditor.vue"; +import ArticleEditor from "@/components/publish/ArticleEditor.vue"; const editor = useEditor() diff --git a/pkg/views/src/views/posts/details.vue b/pkg/views/src/views/posts/details.vue index b4d6204..419d6b7 100644 --- a/pkg/views/src/views/posts/details.vue +++ b/pkg/views/src/views/posts/details.vue @@ -3,10 +3,9 @@
- {{ post?.title }} - -
{{ post?.description }}
+

{{ post?.title }}

+

{{ post?.description }}