From 920492d5a67b86ec2a62bae95f627be871a379e6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 19 Mar 2024 22:52:38 +0800 Subject: [PATCH] :sparkles: Deletable realm :bug: Fix data won't reload after go to another realm --- .../src/components/realms/RealmDeletion.vue | 54 +++++++++++++++++++ .../src/components/realms/RealmEditor.vue | 12 ++++- .../src/components/realms/RealmTools.vue | 4 ++ pkg/views/src/views/realms/page.vue | 11 +++- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 pkg/views/src/components/realms/RealmDeletion.vue diff --git a/pkg/views/src/components/realms/RealmDeletion.vue b/pkg/views/src/components/realms/RealmDeletion.vue new file mode 100644 index 0000000..f2c701e --- /dev/null +++ b/pkg/views/src/components/realms/RealmDeletion.vue @@ -0,0 +1,54 @@ + + + diff --git a/pkg/views/src/components/realms/RealmEditor.vue b/pkg/views/src/components/realms/RealmEditor.vue index b46ff7a..ed7540a 100644 --- a/pkg/views/src/components/realms/RealmEditor.vue +++ b/pkg/views/src/components/realms/RealmEditor.vue @@ -31,7 +31,10 @@ import { ref, watch } from "vue" import { getAtk } from "@/stores/userinfo" import { useRealms } from "@/stores/realms" +import { useRoute, useRouter } from "vue-router" +const route = useRoute() +const router = useRouter() const emits = defineEmits(["relist"]) const realms = useRealms() @@ -56,8 +59,8 @@ async function submit(evt: SubmitEvent) { const payload = data.value if (!payload.name) return - const url = realms.related.edit_to ? `/api/realms/${realms.related.edit_to?.id}` : "/api/moments"; - const method = realms.related.edit_to ? "PUT" : "POST"; + const url = realms.related.edit_to ? `/api/realms/${realms.related.edit_to?.id}` : "/api/realms" + const method = realms.related.edit_to ? "PUT" : "POST" loading.value = true const res = await fetch(url, { @@ -72,6 +75,11 @@ async function submit(evt: SubmitEvent) { form.reset() realms.done = true realms.show.editor = false + realms.related.edit_to = null + + if (route.name?.toString()?.startsWith("realm")) { + router.push({ name: "explore" }) + } } loading.value = false } diff --git a/pkg/views/src/components/realms/RealmTools.vue b/pkg/views/src/components/realms/RealmTools.vue index ceb8332..126ec29 100644 --- a/pkg/views/src/components/realms/RealmTools.vue +++ b/pkg/views/src/components/realms/RealmTools.vue @@ -2,11 +2,15 @@ + + + diff --git a/pkg/views/src/views/realms/page.vue b/pkg/views/src/views/realms/page.vue index 9e22e90..3d1dad3 100644 --- a/pkg/views/src/views/realms/page.vue +++ b/pkg/views/src/views/realms/page.vue @@ -95,8 +95,15 @@ async function readMore({ done }: any) { } } -readMetadata() -readPosts() +watch( + () => route.params.realmId, + () => { + posts.value = [] + readMetadata() + readPosts() + }, + { immediate: true } +) watch(realms, (val) => { if (val.done) {