| 1 | import { defineStore } from 'pinia' |
| 2 | import { ref } from 'vue' |
| 3 | import { getConfig, putConfig, reloadConfig } from '../api/frpc' |
| 4 | |
| 5 | export const useClientStore = defineStore('client', () => { |
| 6 | const config = ref('') |
| 7 | const loading = ref(false) |
| 8 | |
| 9 | const fetchConfig = async () => { |
| 10 | loading.value = true |
| 11 | try { |
| 12 | config.value = await getConfig() |
| 13 | } finally { |
| 14 | loading.value = false |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | const saveConfig = async (text: string) => { |
| 19 | await putConfig(text) |
| 20 | config.value = text |
| 21 | } |
| 22 | |
| 23 | const reload = async () => { |
| 24 | await reloadConfig() |
| 25 | } |
| 26 | |
| 27 | return { config, loading, fetchConfig, saveConfig, reload } |
| 28 | }) |