Interactive/pkg/views/src/stores/realms.ts

38 lines
940 B
TypeScript
Raw Normal View History

2024-03-19 14:03:58 +00:00
import { reactive, ref } from "vue"
import { defineStore } from "pinia"
import { checkLoggedIn, getAtk } from "@/stores/userinfo"
2024-03-23 08:23:21 +00:00
import { request } from "@/scripts/request"
2024-03-19 14:03:58 +00:00
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
2024-03-23 08:23:21 +00:00
const res = await request("/api/realms/me/available", {
2024-03-19 14:03:58 +00:00
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 }
})