schema changes
This commit is contained in:
@@ -10,6 +10,9 @@ interface VehiclesStore {
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<VehicleStatus, "modelUuid" | "productUuid">>
|
||||
) => void;
|
||||
addPathPoint: (modelUuid: string, pathKey: keyof VehicleAction["paths"], point: VehicleAction["paths"]["initPickup"][number]) => VehicleAction["paths"];
|
||||
updatePathPoint: (modelUuid: string, pathKey: keyof VehicleAction["paths"], pointId: string, updates: Partial<VehicleAction["paths"]["initPickup"][number]>) => VehicleAction["paths"];
|
||||
deletePathPoint: (modelUuid: string, pathKey: keyof VehicleAction["paths"], pointId: string) => VehicleAction["paths"];
|
||||
clearVehicles: () => void;
|
||||
|
||||
setVehicleActive: (modelUuid: string, isActive: boolean) => void;
|
||||
@@ -79,6 +82,48 @@ export const createVehicleStore = () => {
|
||||
});
|
||||
},
|
||||
|
||||
addPathPoint: (modelUuid, pathKey, point) => {
|
||||
let updatedPaths: VehicleAction["paths"] = { initPickup: [], pickupDrop: [], dropPickup: [] };
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
if (vehicle) {
|
||||
const path = vehicle.point.action.paths[pathKey];
|
||||
path.push(point);
|
||||
updatedPaths = vehicle.point.action.paths;
|
||||
}
|
||||
});
|
||||
return updatedPaths;
|
||||
},
|
||||
|
||||
updatePathPoint: (modelUuid, pathKey, pointId, updates) => {
|
||||
let updatedPaths: VehicleAction["paths"] = { initPickup: [], pickupDrop: [], dropPickup: [] };
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
if (vehicle) {
|
||||
const path = vehicle.point.action.paths[pathKey];
|
||||
const index = path.findIndex(p => p.pointId === pointId);
|
||||
if (index !== -1) {
|
||||
Object.assign(path[index], updates);
|
||||
updatedPaths = vehicle.point.action.paths;
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedPaths;
|
||||
},
|
||||
|
||||
deletePathPoint: (modelUuid, pathKey, pointId) => {
|
||||
let updatedPaths: VehicleAction["paths"] = { initPickup: [], pickupDrop: [], dropPickup: [] };
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
if (vehicle) {
|
||||
const path = vehicle.point.action.paths[pathKey];
|
||||
vehicle.point.action.paths[pathKey] = path.filter(p => p.pointId !== pointId);
|
||||
updatedPaths = vehicle.point.action.paths;
|
||||
}
|
||||
});
|
||||
return updatedPaths;
|
||||
},
|
||||
|
||||
clearVehicles: () => {
|
||||
set((state) => {
|
||||
state.vehicles = [];
|
||||
|
||||
Reference in New Issue
Block a user