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';
|
|
|
|
import { PlotConfigStorage, EMPTY_PLOTCONFIG } from '@/types';
|
|
|
|
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-11-01 13:45:37 +00:00
|
|
|
plotConfigChanged() {
|
|
|
|
console.log('plotConfigChanged');
|
|
|
|
this.plotConfig = getCustomPlotConfig(this.plotConfigName);
|
|
|
|
this.setPlotConfigName(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
|
|
|
},
|
|
|
|
});
|