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,
2022-11-01 13:45:37 +00:00
getCustomPlotConfig,
2022-11-01 13:10:59 +00:00
getPlotConfigName,
storeCustomPlotConfig,
storePlotConfigName,
} from '@/shared/storage';
2022-11-01 16:33:31 +00:00
import { PlotConfigStorage, EMPTY_PLOTCONFIG, PlotConfig } from '@/types';
2022-11-01 13:10:59 +00:00
import { defineStore } from 'pinia';
export const usePlotConfigStore = defineStore('plotConfig', {
state: () => {
return {
customPlotConfig: {} as PlotConfigStorage,
plotConfigName: getPlotConfigName(),
availablePlotConfigNames: getAllPlotConfigNames(),
2022-11-01 13:45:37 +00:00
plotConfig: { ...EMPTY_PLOTCONFIG },
2022-11-01 13:10:59 +00:00
};
},
getters: {
2022-11-01 13:45:37 +00:00
// plotConfig: (state) => state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG },
2022-11-01 13:10:59 +00:00
},
actions: {
saveCustomPlotConfig(plotConfig: PlotConfigStorage) {
this.customPlotConfig = plotConfig;
storeCustomPlotConfig(plotConfig);
this.availablePlotConfigNames = getAllPlotConfigNames();
},
setPlotConfigName(plotConfigName: string) {
this.plotConfigName = plotConfigName;
storePlotConfigName(plotConfigName);
},
2022-12-20 00:22:29 +00:00
plotConfigChanged(plotConfigName = '') {
2022-11-01 13:45:37 +00:00
console.log('plotConfigChanged');
2022-12-20 00:22:29 +00:00
this.setPlotConfigName(plotConfigName ? plotConfigName : this.plotConfigName);
2022-11-01 13:45:37 +00:00
this.plotConfig = getCustomPlotConfig(this.plotConfigName);
},
2022-11-01 15:18:12 +00:00
setPlotConfig(plotConfig: PlotConfig) {
console.log('emit...');
this.plotConfig = { ...plotConfig };
},
2022-11-01 13:10:59 +00:00
},
});