basic module setup
This commit is contained in:
+37
-2
@@ -1,7 +1,8 @@
|
||||
import { createSignal } from 'solid-js';
|
||||
import { createStore } from 'solid-js/store';
|
||||
import { createStore, produce } from 'solid-js/store';
|
||||
import type { ExtractedItem } from '../utils/csv-parser';
|
||||
import type { TemplateItem, Scope, SubScope, EstimateItem, JobInfo } from '../types';
|
||||
import type { TemplateItem, Scope, SubScope, EstimateItem, JobInfo, Modifier } from '../types';
|
||||
import { ModifierRegistry } from '../utils/modifier-registry';
|
||||
|
||||
// Raw CSV Data
|
||||
const [activeItems, setActiveItems] = createSignal<ExtractedItem[]>([]);
|
||||
@@ -68,6 +69,40 @@ export const appStore = {
|
||||
jobInfo, setJobInfo,
|
||||
generalEstimateNotes, setGeneralEstimateNotes,
|
||||
generalPreNotes, setGeneralPreNotes,
|
||||
// Scopes
|
||||
addModifier(subScopeId: string, moduleId: string) {
|
||||
const module = ModifierRegistry.getModule(moduleId);
|
||||
const newModifier: Modifier = {
|
||||
id: Math.random().toString(36).substr(2, 9),
|
||||
moduleId: module.id,
|
||||
name: module.defaultLabel,
|
||||
value: module.defaultValue,
|
||||
valueType: module.defaultValueType,
|
||||
unitLabel: module.defaultUnitLabel,
|
||||
type: module.id as any, // Temporary cast
|
||||
includeInTotal: module.id !== 'man-hours'
|
||||
};
|
||||
|
||||
setSubScopes(s => s.id === subScopeId, produce((ss) => {
|
||||
if (!ss.modifiers) ss.modifiers = [];
|
||||
ss.modifiers.push(newModifier);
|
||||
}));
|
||||
},
|
||||
updateModifier: (subScopeId: string, modifierId: string, updates: Partial<Modifier>) => {
|
||||
setSubScopes(
|
||||
s => s.id === subScopeId,
|
||||
'modifiers',
|
||||
(m: Modifier) => m.id === modifierId,
|
||||
updates
|
||||
);
|
||||
},
|
||||
removeModifier: (subScopeId: string, modifierId: string) => {
|
||||
setSubScopes(
|
||||
s => s.id === subScopeId,
|
||||
'modifiers',
|
||||
(m = []) => m.filter(mod => mod.id !== modifierId)
|
||||
);
|
||||
},
|
||||
|
||||
// Templates
|
||||
templateId: activeTemplateId,
|
||||
|
||||
Reference in New Issue
Block a user