Display Settings
This commit is contained in:
parent
b7dd5a95cd
commit
6f155ada66
7 changed files with 170 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import { type SettingString, type SettingValueMapping } from "@/types/settingTypes";
|
||||
import type { SettingString, SettingTopic, SettingValueMapping } from "@/types/settingTypes";
|
||||
import type { AxiosResponse } from "axios";
|
||||
|
||||
export const useSettingStore = defineStore("setting", {
|
||||
|
@ -16,6 +16,19 @@ export const useSettingStore = defineStore("setting", {
|
|||
<K extends SettingString>(key: K): SettingValueMapping[K] => {
|
||||
return state.settings[key];
|
||||
},
|
||||
readByTopic:
|
||||
(state) =>
|
||||
<T extends SettingTopic>(
|
||||
topic: T
|
||||
): { [K in SettingString as K extends `${T}.${string}` ? K : never]: SettingValueMapping[K] } => {
|
||||
return Object.entries(state.settings).reduce((acc, [key, value]) => {
|
||||
const typedKey = key as SettingString;
|
||||
if (key.startsWith(topic)) {
|
||||
acc[typedKey] = value;
|
||||
}
|
||||
return acc;
|
||||
}, {} as any);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
fetchSettings() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue