56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import AppState from "../classes/AppState";
|
|
|
|
export const useAppStore = defineStore("appStore", {
|
|
state: () => ({
|
|
data: new AppState({} as TypeApp),
|
|
activeBrand: null,
|
|
activeRange: null,
|
|
} as {
|
|
data: AppState;
|
|
activeBrand: TypeBrand | null;
|
|
activeRange: TypeRange | null;
|
|
}),
|
|
actions: {
|
|
setupAppData(dataJson: TypeApp): void {
|
|
this.data = new AppState(dataJson);
|
|
},
|
|
setActiveBrand(brand: TypeBrand|null): void {
|
|
this.activeBrand = brand;
|
|
},
|
|
setActiveRange(range: TypeRange|null): void {
|
|
this.activeRange = range;
|
|
},
|
|
getNextRange(): TypeRange | null {
|
|
if (!this.activeRange) {
|
|
return null;
|
|
}
|
|
const ranges = this.data.ranges(this.data.brandFromRange(this.activeRange));
|
|
const activeRangeIndex = ranges.findIndex(range => this.activeRange!.id === range.id);
|
|
return activeRangeIndex === -1 ? null :
|
|
ranges.at(activeRangeIndex+1) ?? null;
|
|
},
|
|
getPreviousRange(): TypeRange| null {
|
|
if (!this.activeRange) {
|
|
return null;
|
|
}
|
|
const ranges = this.data.ranges(this.data.brandFromRange(this.activeRange));
|
|
const activeRangeIndex = ranges.findIndex(range => this.activeRange!.id === range.id);
|
|
return (activeRangeIndex === -1 || (activeRangeIndex-1 < 0)) ? null :
|
|
ranges.at(activeRangeIndex-1) ?? null;
|
|
},
|
|
getSettings(): TypeSettings {
|
|
return this.data.settings();
|
|
},
|
|
getFont(fontId: number): TypeFont | null {
|
|
const font = this.data.font(fontId);
|
|
if (!font) {
|
|
return null;
|
|
}
|
|
return font;
|
|
}
|
|
}
|
|
});
|
|
|
|
if (import.meta.hot) {
|
|
import.meta.hot.accept(acceptHMRUpdate(useAppStore, import.meta.hot));
|
|
}
|