Editable realm

This commit is contained in:
2024-03-19 22:03:58 +08:00
parent 2f87f9bc32
commit c14d3f70a3
11 changed files with 258 additions and 164 deletions

View File

@ -1,6 +1,5 @@
import { defineStore } from "pinia"
import { reactive, ref } from "vue"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
export const useEditor = defineStore("editor", () => {
const done = ref(false)
@ -26,22 +25,5 @@ export const useEditor = defineStore("editor", () => {
delete_to: null
})
const availableRealms = ref<any[]>([])
async function listRealms() {
if (!checkLoggedIn()) return
const res = await fetch("/api/realms/me/available", {
headers: { Authorization: `Bearer ${getAtk()}` }
})
if (res.status !== 200) {
throw new Error(await res.text())
} else {
availableRealms.value = await res.json()
}
}
listRealms().then(() => console.log("[STARTUP HOOK] Fetch available realm successes."))
return { show, related, availableRealms, listRealms, done }
return { show, related, done }
})

View File

@ -0,0 +1,36 @@
import { reactive, ref } from "vue"
import { defineStore } from "pinia"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
export const useRealms = defineStore("realms", () => {
const done = ref(false)
const show = reactive({
editor: false,
delete: false
})
const related_to = reactive<{ edit_to: any; delete_to: any }>({
edit_to: null,
delete_to: null
})
const available = ref<any[]>([])
async function list() {
if (!checkLoggedIn()) return
const res = await fetch("/api/realms/me/available", {
headers: { Authorization: `Bearer ${getAtk()}` }
})
if (res.status !== 200) {
throw new Error(await res.text())
} else {
available.value = await res.json()
}
}
list().then(() => console.log("[STARTUP HOOK] Fetch available realm successes."))
return { done, show, related: related_to, available, list }
})