-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathconfig.js
More file actions
45 lines (41 loc) · 978 Bytes
/
config.js
File metadata and controls
45 lines (41 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { configApi } from '../api/config'
export const useConfigStore = defineStore('config', () => {
const config = ref(null)
const loading = ref(false)
const error = ref(null)
const fetchConfig = async () => {
loading.value = true
error.value = null
try {
config.value = await configApi.getConfig()
} catch (e) {
error.value = e.message
console.error('Failed to fetch config:', e)
} finally {
loading.value = false
}
}
const updateConfig = async (key, value) => {
loading.value = true
error.value = null
try {
await configApi.updateConfig(key, value)
await fetchConfig()
} catch (e) {
error.value = e.message
console.error('Failed to update config:', e)
throw e
} finally {
loading.value = false
}
}
return {
config,
loading,
error,
fetchConfig,
updateConfig
}
})