From 9bc387cb86310ac7091edc96db4d782d27860c40 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 4 Apr 2024 18:35:48 +0800 Subject: [PATCH] :art: Deconstruct the snackbar --- src/components/chat/ChatEditor.vue | 17 +++----------- src/components/chat/MessageDeletion.vue | 13 ++++------- .../chat/channels/ChannelDeletion.vue | 13 ++++------- .../chat/channels/ChannelEditor.vue | 8 +++---- .../chat/channels/ChannelMembers.vue | 15 +++++-------- src/components/{ => common}/Copyright.vue | 0 src/components/common/SnackbarProvider.vue | 20 +++++++++++++++++ src/components/posts/PostReaction.vue | 17 +++++--------- src/components/publish/ArticleEditor.vue | 20 +++++++---------- src/components/publish/CommentEditor.vue | 13 ++++------- src/components/publish/MomentEditor.vue | 17 ++++++-------- src/components/publish/PostDeletion.vue | 13 ++++------- src/components/publish/parts/PublishMedia.vue | 1 - src/components/realms/RealmDeletion.vue | 13 ++++------- src/components/realms/RealmEditor.vue | 8 +++---- src/components/realms/RealmMembers.vue | 15 +++++-------- .../{ => users}/NotificationList.vue | 9 +++----- src/components/{ => users}/UserMenu.vue | 0 src/index.vue | 6 +++-- src/layouts/chat.vue | 10 ++++----- src/layouts/master.vue | 2 +- src/stores/ui.ts | 22 ++++++++++++++++--- src/views/auth/sign-in.vue | 2 +- src/views/auth/sign-up.vue | 2 +- src/views/chat/page.vue | 21 +++++++++--------- src/views/explore.vue | 20 +++++++++-------- src/views/users/page.vue | 6 ++--- 27 files changed, 138 insertions(+), 165 deletions(-) rename src/components/{ => common}/Copyright.vue (100%) create mode 100644 src/components/common/SnackbarProvider.vue rename src/components/{ => users}/NotificationList.vue (90%) rename src/components/{ => users}/UserMenu.vue (100%) diff --git a/src/components/chat/ChatEditor.vue b/src/components/chat/ChatEditor.vue index fea8242..2fefc53 100644 --- a/src/components/chat/ChatEditor.vue +++ b/src/components/chat/ChatEditor.vue @@ -103,9 +103,6 @@ Uploading your media, please stand by... - - - Something went wrong... {{ error }} @@ -114,15 +111,15 @@ import { reactive, ref, watch } from "vue" import { request } from "@/scripts/request" import { getAtk } from "@/stores/userinfo" import { useChannels } from "@/stores/channels" +import { useUI } from "@/stores/ui" import Attachments from "@/components/chat/parts/ChatAttachments.vue" -import Media from "@/components/publish/parts/PublishMedia.vue" const emits = defineEmits(["sent"]) const chat = ref() const channels = useChannels() -const error = ref(null) +const { showErrorSnackbar } = useUI() const uploading = ref(false) const loading = ref(false) @@ -156,11 +153,10 @@ async function sendMessage() { body: JSON.stringify(payload) }) if (res.status !== 200) { - error.value = await res.text() + showErrorSnackbar(await res.text()) } else { emits("sent") resetEditor() - error.value = null } loading.value = false } @@ -203,10 +199,3 @@ function pasteMedia(evt: ClipboardEvent) { } } - - diff --git a/src/components/chat/MessageDeletion.vue b/src/components/chat/MessageDeletion.vue index d78be98..2dd01b3 100644 --- a/src/components/chat/MessageDeletion.vue +++ b/src/components/chat/MessageDeletion.vue @@ -12,11 +12,6 @@ - - The realm has been deleted. - - - Something went wrong... {{ error }} + + \ No newline at end of file diff --git a/src/components/posts/PostReaction.vue b/src/components/posts/PostReaction.vue index bfacece..a183601 100644 --- a/src/components/posts/PostReaction.vue +++ b/src/components/posts/PostReaction.vue @@ -26,12 +26,6 @@ - - Your react has been added into post. - Your react has been removed from post. - - - Something went wrong... {{ error }} @@ -39,8 +33,10 @@ import { request } from "@/scripts/request" import { getAtk, useUserinfo } from "@/stores/userinfo" import { reactive, ref } from "vue" +import { useUI } from "@/stores/ui" const id = useUserinfo() +const {showSnackbar, showErrorSnackbar} = useUI() const emits = defineEmits(["update"]) const props = defineProps<{ @@ -62,9 +58,6 @@ function pickColor(): string { return colors[randomIndex] } -const status = reactive({ added: false, removed: false }) -const error = ref(null) - async function reactPost(symbol: string, attitude: number) { const res = await request("interactive", `/api/p/${props.model}/${props.item?.id}/react`, { method: "POST", @@ -72,13 +65,13 @@ async function reactPost(symbol: string, attitude: number) { body: JSON.stringify({ symbol, attitude }) }) if (res.status === 201) { - status.added = true + showSnackbar("Your react has been added onto the post.") emits("update", symbol, 1) } else if (res.status === 204) { - status.removed = true + showSnackbar("Your react has been removed from the post.") emits("update", symbol, -1) } else { - error.value = await res.text() + showErrorSnackbar(await res.text()) } } diff --git a/src/components/publish/ArticleEditor.vue b/src/components/publish/ArticleEditor.vue index 79b8802..4e8fa5a 100644 --- a/src/components/publish/ArticleEditor.vue +++ b/src/components/publish/ArticleEditor.vue @@ -109,14 +109,10 @@ - Your article has been published. Uploading your media, please stand by... - - - Something went wrong... {{ error }}