frequi_origin/src/stores/plotConfig.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-11-01 13:10:59 +00:00
import {
getAllPlotConfigNames,
getPlotConfigName,
storeCustomPlotConfig,
storePlotConfigName,
} from '@/shared/storage';
import { PlotConfigStorage, EMPTY_PLOTCONFIG } from '@/types';
import { defineStore } from 'pinia';
export const usePlotConfigStore = defineStore('plotConfig', {
state: () => {
return {
customPlotConfig: {} as PlotConfigStorage,
plotConfigName: getPlotConfigName(),
availablePlotConfigNames: getAllPlotConfigNames(),
};
},
getters: {
plotConfig: (state) => state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG },
},
actions: {
saveCustomPlotConfig(plotConfig: PlotConfigStorage) {
this.customPlotConfig = plotConfig;
storeCustomPlotConfig(plotConfig);
this.availablePlotConfigNames = getAllPlotConfigNames();
},
updatePlotConfigName(plotConfigName: string) {
// Set default plot config name
this.plotConfigName = plotConfigName;
storePlotConfigName(plotConfigName);
},
setPlotConfigName(plotConfigName: string) {
// TODO: This is identical to updatePlotConfigName
this.plotConfigName = plotConfigName;
storePlotConfigName(plotConfigName);
},
// plotConfigChanged() {
// console.log('plotConfigChanged');
// plotConfig.value = getCustomPlotConfig(this.plotConfigName);
// plotStore.setPlotConfigName(plotConfigName.value);
// },
},
});