44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { useAppStore } from "../stores/useAppStore";
|
|
|
|
export default class AppState {
|
|
/** Json data as exported from zip and compliant with schemas */
|
|
private jsonData: TypeApp;
|
|
|
|
/** The selected brand */
|
|
private selectedBrand: TypeBrand | null = null;
|
|
|
|
constructor(jsonData: TypeApp) {
|
|
this.jsonData = jsonData;
|
|
}
|
|
|
|
public settings(): TypeSettings {
|
|
return this.jsonData.settings;
|
|
}
|
|
|
|
// * --- BRANDS
|
|
|
|
public brands(): Array<TypeBrand> {
|
|
return this.jsonData.items;
|
|
}
|
|
|
|
public brand(slug:string): TypeBrand|undefined {
|
|
return this.jsonData.items.find(brand => brand.slug === slug);
|
|
}
|
|
|
|
public useBrand(brand: TypeBrand) {
|
|
this.selectedBrand = brand;
|
|
useAppStore().setActiveBrand(null);
|
|
clearNuxtState("ranges");
|
|
useState("ranges", (): Array<TypeRange> => brand.ranges);
|
|
}
|
|
|
|
// * --- END BRANDS
|
|
|
|
// * --- RANGES
|
|
|
|
public ranges(): Array<TypeRange> {
|
|
return useState("ranges", (): Array<TypeRange> => []).value;
|
|
}
|
|
|
|
// * --- END RANGES
|
|
}
|