updated
This commit is contained in:
@@ -27,7 +27,6 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
const dashBoardSocket = io(
|
||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/dashboard`,
|
||||
{
|
||||
@@ -42,8 +41,21 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||
auth: { token },
|
||||
}
|
||||
);
|
||||
const threadSocket = io(
|
||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/thread`,
|
||||
{
|
||||
reconnection: true,
|
||||
auth: { token },
|
||||
}
|
||||
);
|
||||
|
||||
set({ socket, visualizationSocket, dashBoardSocket, projectSocket });
|
||||
set({
|
||||
socket,
|
||||
visualizationSocket,
|
||||
dashBoardSocket,
|
||||
projectSocket,
|
||||
threadSocket,
|
||||
});
|
||||
},
|
||||
disconnectSocket: () => {
|
||||
set((state: any) => {
|
||||
@@ -51,6 +63,7 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||
state.visualizationSocket?.disconnect();
|
||||
state.dashBoardSocket?.disconnect();
|
||||
state.projectSocket?.disconnect();
|
||||
state.threadSocket?.disconnect();
|
||||
return { socket: null };
|
||||
});
|
||||
},
|
||||
@@ -515,15 +528,15 @@ export const useZoneAssetId = create<ZoneAssetState>((set) => ({
|
||||
// version visible hidden
|
||||
interface VersionHistoryState {
|
||||
viewVersionHistory: boolean;
|
||||
setVersionHistory: (value: boolean) => void;
|
||||
setVersionHistoryVisible: (value: boolean) => void;
|
||||
}
|
||||
|
||||
const useVersionHistoryStore = create<VersionHistoryState>((set) => ({
|
||||
const useVersionHistoryVisibleStore = create<VersionHistoryState>((set) => ({
|
||||
viewVersionHistory: false,
|
||||
setVersionHistory: (value) => set({ viewVersionHistory: value }),
|
||||
setVersionHistoryVisible: (value) => set({ viewVersionHistory: value }),
|
||||
}));
|
||||
|
||||
export default useVersionHistoryStore;
|
||||
export default useVersionHistoryVisibleStore;
|
||||
|
||||
interface ShortcutStore {
|
||||
showShortcuts: boolean;
|
||||
@@ -647,47 +660,6 @@ export const useSaveVersion = create<SaveVersionStore>((set) => ({
|
||||
setIsVersionSaved: (value: boolean) => set({ isVersionSaved: value }),
|
||||
}));
|
||||
|
||||
// Version object type
|
||||
export interface Version {
|
||||
id: string;
|
||||
versionLabel: string;
|
||||
versionName?: string;
|
||||
timestamp: string;
|
||||
savedBy: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
// Version list store
|
||||
interface VersionListStore {
|
||||
versions: Version[];
|
||||
addVersion: (version: Version) => void;
|
||||
clearVersions: () => void;
|
||||
setVersions: (newVersions: Version[]) => void;
|
||||
updateVersion: (id: string, data: Partial<Version>) => void; // ✅ Added
|
||||
}
|
||||
|
||||
export const useVersionStore = create<VersionListStore>((set) => ({
|
||||
versions: [],
|
||||
|
||||
addVersion: (newVersion) =>
|
||||
set((state) => ({
|
||||
versions: [newVersion, ...state.versions],
|
||||
})),
|
||||
|
||||
clearVersions: () => set({ versions: [] }),
|
||||
|
||||
setVersions: (newVersions) => set({ versions: newVersions }),
|
||||
|
||||
updateVersion: (id, data) =>
|
||||
set((state) => ({
|
||||
versions: state.versions.map((version) =>
|
||||
version.id === id ? { ...version, ...data } : version
|
||||
),
|
||||
})),
|
||||
}));
|
||||
|
||||
|
||||
|
||||
interface ViewSceneState {
|
||||
viewSceneLabels: boolean;
|
||||
setViewSceneLabels: (value: boolean | ((prev: boolean) => boolean)) => void;
|
||||
@@ -698,10 +670,10 @@ export const useViewSceneStore = create<ViewSceneState>((set) => ({
|
||||
setViewSceneLabels: (value) => {
|
||||
set((state) => {
|
||||
const newValue =
|
||||
typeof value === 'function' ? value(state.viewSceneLabels) : value;
|
||||
typeof value === "function" ? value(state.viewSceneLabels) : value;
|
||||
|
||||
// Store in localStorage manually
|
||||
localStorage.setItem('viewSceneLabels', JSON.stringify(newValue));
|
||||
localStorage.setItem("viewSceneLabels", JSON.stringify(newValue));
|
||||
|
||||
return { viewSceneLabels: newValue };
|
||||
});
|
||||
@@ -709,8 +681,8 @@ export const useViewSceneStore = create<ViewSceneState>((set) => ({
|
||||
}));
|
||||
|
||||
function getInitialViewSceneLabels(): boolean {
|
||||
if (typeof window === 'undefined') return false; // SSR safety
|
||||
const saved = localStorage.getItem('viewSceneLabels');
|
||||
if (typeof window === "undefined") return false; // SSR safety
|
||||
const saved = localStorage.getItem("viewSceneLabels");
|
||||
return saved ? JSON.parse(saved) : false;
|
||||
}
|
||||
export interface CompareProduct {
|
||||
@@ -732,7 +704,7 @@ export interface CompareProduct {
|
||||
machineIdleTime: number;
|
||||
machineActiveTime: number;
|
||||
throughputData: number;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const useCompareProductDataStore = create<{
|
||||
@@ -741,4 +713,13 @@ export const useCompareProductDataStore = create<{
|
||||
}>((set) => ({
|
||||
compareProductsData: [],
|
||||
setCompareProductsData: (x) => set({ compareProductsData: x }),
|
||||
}));
|
||||
}));
|
||||
|
||||
export const useSelectedComment = create<any>((set: any) => ({
|
||||
selectedComment: null,
|
||||
setSelectedComment: (x: any) => set({ selectedComment: x }),
|
||||
position2Dstate: {},
|
||||
setPosition2Dstate: (x: any) => set({ position2Dstate: x }),
|
||||
commentPositionState: null,
|
||||
setCommentPositionState: (x: any) => set({ commentPositionState: x }),
|
||||
}));
|
||||
|
||||
@@ -2,246 +2,250 @@ import { create } from "zustand";
|
||||
import { immer } from "zustand/middleware/immer";
|
||||
|
||||
interface AisleStore {
|
||||
aisles: Aisles;
|
||||
setAisles: (aisles: Aisles) => void;
|
||||
addAisle: (aisle: Aisle) => void;
|
||||
updateAisle: (uuid: string, updated: Partial<Aisle>) => void;
|
||||
removeAisle: (uuid: string) => void;
|
||||
removePoint: (uuid: string) => Aisles;
|
||||
setPosition: (
|
||||
pointUuid: string,
|
||||
position: [number, number, number]
|
||||
) => Aisle | undefined;
|
||||
setLayer: (pointUuid: string, layer: number) => void;
|
||||
setColor: (aisleUuid: string, color: AisleColors) => void;
|
||||
aisles: Aisles;
|
||||
setAisles: (aisles: Aisles) => void;
|
||||
addAisle: (aisle: Aisle) => void;
|
||||
updateAisle: (uuid: string, updated: Partial<Aisle>) => void;
|
||||
removeAisle: (uuid: string) => void;
|
||||
removePoint: (uuid: string) => Aisles;
|
||||
setPosition: (
|
||||
pointUuid: string,
|
||||
position: [number, number, number]
|
||||
) => Aisle | undefined;
|
||||
setLayer: (pointUuid: string, layer: number) => void;
|
||||
setColor: (aisleUuid: string, color: AisleColors) => void;
|
||||
|
||||
// Type-specific setters
|
||||
setSolidAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setDashedAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; dashLength?: number; gapLength?: number }
|
||||
) => void;
|
||||
setDottedAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { dotRadius?: number; gapLength?: number }
|
||||
) => void;
|
||||
setArrowAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setArrowsAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; aisleLength?: number; gapLength?: number }
|
||||
) => void;
|
||||
setArcAisleWidth: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; isFlipped: boolean }
|
||||
) => void;
|
||||
setCircleAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setJunctionAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; isFlipped: boolean }
|
||||
) => void;
|
||||
// Type-specific setters
|
||||
setSolidAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setDashedAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; dashLength?: number; gapLength?: number }
|
||||
) => void;
|
||||
setDottedAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { dotRadius?: number; gapLength?: number }
|
||||
) => void;
|
||||
setArrowAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setArrowsAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; aisleLength?: number; gapLength?: number }
|
||||
) => void;
|
||||
setArcAisleWidth: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; isFlipped: boolean }
|
||||
) => void;
|
||||
setCircleAisleWidth: (aisleUuid: string, width: number) => void;
|
||||
setJunctionAisleProperties: (
|
||||
aisleUuid: string,
|
||||
props: { aisleWidth?: number; isFlipped: boolean }
|
||||
) => void;
|
||||
|
||||
getAisleById: (uuid: string) => Aisle | undefined;
|
||||
getAislesByPointId: (uuid: string) => Aisle[] | [];
|
||||
getAislePointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[] | [];
|
||||
getAisleType: <T extends AisleType>(uuid: string) => T | undefined;
|
||||
getAisleById: (uuid: string) => Aisle | undefined;
|
||||
getAislesByPointId: (uuid: string) => Aisle[] | [];
|
||||
getAislePointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[] | [];
|
||||
getAisleType: <T extends AisleType>(uuid: string) => T | undefined;
|
||||
}
|
||||
|
||||
export const useAisleStore = create<AisleStore>()(
|
||||
immer((set, get) => ({
|
||||
aisles: [],
|
||||
export const createAisleStore = () => {
|
||||
return create<AisleStore>()(
|
||||
immer((set, get) => ({
|
||||
aisles: [],
|
||||
|
||||
setAisles: (aisles) =>
|
||||
set((state) => {
|
||||
state.aisles = aisles;
|
||||
}),
|
||||
setAisles: (aisles) =>
|
||||
set((state) => {
|
||||
state.aisles = aisles;
|
||||
}),
|
||||
|
||||
addAisle: (aisle) =>
|
||||
set((state) => {
|
||||
state.aisles.push(aisle);
|
||||
}),
|
||||
addAisle: (aisle) =>
|
||||
set((state) => {
|
||||
state.aisles.push(aisle);
|
||||
}),
|
||||
|
||||
updateAisle: (uuid, updated) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === uuid);
|
||||
if (aisle) {
|
||||
Object.assign(aisle, updated);
|
||||
}
|
||||
}),
|
||||
updateAisle: (uuid, updated) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === uuid);
|
||||
if (aisle) {
|
||||
Object.assign(aisle, updated);
|
||||
}
|
||||
}),
|
||||
|
||||
removeAisle: (uuid) =>
|
||||
set((state) => {
|
||||
state.aisles = state.aisles.filter((a) => a.aisleUuid !== uuid);
|
||||
}),
|
||||
removeAisle: (uuid) =>
|
||||
set((state) => {
|
||||
state.aisles = state.aisles.filter((a) => a.aisleUuid !== uuid);
|
||||
}),
|
||||
|
||||
removePoint: (uuid) => {
|
||||
const removedAisles: Aisle[] = [];
|
||||
set((state) => {
|
||||
state.aisles = state.aisles.filter((aisle) => {
|
||||
const hasPoint = aisle.points.some(
|
||||
(point) => point.pointUuid === uuid
|
||||
);
|
||||
if (hasPoint) {
|
||||
removedAisles.push(JSON.parse(JSON.stringify(aisle)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
return removedAisles;
|
||||
},
|
||||
removePoint: (uuid) => {
|
||||
const removedAisles: Aisle[] = [];
|
||||
set((state) => {
|
||||
state.aisles = state.aisles.filter((aisle) => {
|
||||
const hasPoint = aisle.points.some(
|
||||
(point) => point.pointUuid === uuid
|
||||
);
|
||||
if (hasPoint) {
|
||||
removedAisles.push(JSON.parse(JSON.stringify(aisle)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
});
|
||||
return removedAisles;
|
||||
},
|
||||
|
||||
setPosition: (pointUuid, position) => {
|
||||
let updatedAisle: Aisle | undefined;
|
||||
set((state) => {
|
||||
for (const aisle of state.aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.position = position;
|
||||
updatedAisle = JSON.parse(JSON.stringify(aisle));
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedAisle;
|
||||
},
|
||||
setPosition: (pointUuid, position) => {
|
||||
let updatedAisle: Aisle | undefined;
|
||||
set((state) => {
|
||||
for (const aisle of state.aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.position = position;
|
||||
updatedAisle = JSON.parse(JSON.stringify(aisle));
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedAisle;
|
||||
},
|
||||
|
||||
setLayer: (pointUuid, layer) =>
|
||||
set((state) => {
|
||||
for (const aisle of state.aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.layer = layer;
|
||||
}
|
||||
}
|
||||
}),
|
||||
setLayer: (pointUuid, layer) =>
|
||||
set((state) => {
|
||||
for (const aisle of state.aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === pointUuid);
|
||||
if (point) {
|
||||
point.layer = layer;
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
setColor: (aisleUuid, color) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle) {
|
||||
aisle.type.aisleColor = color;
|
||||
}
|
||||
}),
|
||||
setColor: (aisleUuid, color) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle) {
|
||||
aisle.type.aisleColor = color;
|
||||
}
|
||||
}),
|
||||
|
||||
// Type-specific property setters
|
||||
setSolidAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "solid-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
// Type-specific property setters
|
||||
setSolidAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "solid-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
|
||||
setDashedAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "dashed-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.dashLength !== undefined)
|
||||
aisle.type.dashLength = props.dashLength;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
setDashedAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "dashed-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.dashLength !== undefined)
|
||||
aisle.type.dashLength = props.dashLength;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
|
||||
setDottedAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "dotted-aisle") {
|
||||
if (props.dotRadius !== undefined)
|
||||
aisle.type.dotRadius = props.dotRadius;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
setDottedAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "dotted-aisle") {
|
||||
if (props.dotRadius !== undefined)
|
||||
aisle.type.dotRadius = props.dotRadius;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
|
||||
setArrowAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arrow-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
setArrowAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arrow-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
|
||||
setArrowsAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arrows-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.aisleLength !== undefined)
|
||||
aisle.type.aisleLength = props.aisleLength;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
setArrowsAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arrows-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.aisleLength !== undefined)
|
||||
aisle.type.aisleLength = props.aisleLength;
|
||||
if (props.gapLength !== undefined)
|
||||
aisle.type.gapLength = props.gapLength;
|
||||
}
|
||||
}),
|
||||
|
||||
setArcAisleWidth: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arc-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.isFlipped !== undefined)
|
||||
aisle.type.isFlipped = props.isFlipped;
|
||||
}
|
||||
}),
|
||||
setArcAisleWidth: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "arc-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.isFlipped !== undefined)
|
||||
aisle.type.isFlipped = props.isFlipped;
|
||||
}
|
||||
}),
|
||||
|
||||
setCircleAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "circle-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
setCircleAisleWidth: (aisleUuid, width) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "circle-aisle") {
|
||||
aisle.type.aisleWidth = width;
|
||||
}
|
||||
}),
|
||||
|
||||
setJunctionAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "junction-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.isFlipped !== undefined)
|
||||
aisle.type.isFlipped = props.isFlipped;
|
||||
}
|
||||
}),
|
||||
setJunctionAisleProperties: (aisleUuid, props) =>
|
||||
set((state) => {
|
||||
const aisle = state.aisles.find((a) => a.aisleUuid === aisleUuid);
|
||||
if (aisle && aisle.type.aisleType === "junction-aisle") {
|
||||
if (props.aisleWidth !== undefined)
|
||||
aisle.type.aisleWidth = props.aisleWidth;
|
||||
if (props.isFlipped !== undefined)
|
||||
aisle.type.isFlipped = props.isFlipped;
|
||||
}
|
||||
}),
|
||||
|
||||
getAisleById: (uuid) => {
|
||||
return get().aisles.find((a) => a.aisleUuid === uuid);
|
||||
},
|
||||
getAisleById: (uuid) => {
|
||||
return get().aisles.find((a) => a.aisleUuid === uuid);
|
||||
},
|
||||
|
||||
getAislesByPointId: (uuid) => {
|
||||
return get().aisles.filter((a) => {
|
||||
return a.points.some((p) => p.pointUuid === uuid);
|
||||
})
|
||||
},
|
||||
getAislesByPointId: (uuid) => {
|
||||
return get().aisles.filter((a) => {
|
||||
return a.points.some((p) => p.pointUuid === uuid);
|
||||
})
|
||||
},
|
||||
|
||||
getAislePointById: (uuid) => {
|
||||
for (const aisle of get().aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === uuid);
|
||||
if (point) {
|
||||
return point;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
getAislePointById: (uuid) => {
|
||||
for (const aisle of get().aisles) {
|
||||
const point = aisle.points.find((p) => p.pointUuid === uuid);
|
||||
if (point) {
|
||||
return point;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getConnectedPoints: (uuid) => {
|
||||
const connected: Point[] = [];
|
||||
for (const aisle of get().aisles) {
|
||||
for (const point of aisle.points) {
|
||||
if (point.pointUuid === uuid) {
|
||||
connected.push(...aisle.points.filter((p) => p.pointUuid !== uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return connected;
|
||||
},
|
||||
getConnectedPoints: (uuid) => {
|
||||
const connected: Point[] = [];
|
||||
for (const aisle of get().aisles) {
|
||||
for (const point of aisle.points) {
|
||||
if (point.pointUuid === uuid) {
|
||||
connected.push(...aisle.points.filter((p) => p.pointUuid !== uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return connected;
|
||||
},
|
||||
|
||||
getAisleType: <T extends AisleType>(uuid: string) => {
|
||||
const aisle = get().aisles.find((a) => a.aisleUuid === uuid);
|
||||
return aisle?.type as T | undefined;
|
||||
},
|
||||
}))
|
||||
);
|
||||
getAisleType: <T extends AisleType>(uuid: string) => {
|
||||
const aisle = get().aisles.find((a) => a.aisleUuid === uuid);
|
||||
return aisle?.type as T | undefined;
|
||||
},
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
export type AisleStoreType = ReturnType<typeof createAisleStore>;
|
||||
@@ -8,6 +8,7 @@ interface AssetsStore {
|
||||
addAsset: (asset: Asset) => void;
|
||||
removeAsset: (modelUuid: string) => void;
|
||||
updateAsset: (modelUuid: string, updates: Partial<Asset>) => void;
|
||||
clearAssets: () => void;
|
||||
setAssets: (assets: Assets) => void;
|
||||
|
||||
// Asset properties
|
||||
@@ -36,196 +37,206 @@ interface AssetsStore {
|
||||
hasAsset: (modelUuid: string) => boolean;
|
||||
}
|
||||
|
||||
export const useAssetsStore = create<AssetsStore>()(
|
||||
immer((set, get) => ({
|
||||
assets: [],
|
||||
export const createAssetStore = () => {
|
||||
return create<AssetsStore>()(
|
||||
immer((set, get) => ({
|
||||
assets: [],
|
||||
|
||||
// Asset CRUD operations
|
||||
addAsset: (asset) => {
|
||||
set((state) => {
|
||||
if (!state.assets.some(a => a.modelUuid === asset.modelUuid)) {
|
||||
state.assets.push(asset);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeAsset: (modelUuid) => {
|
||||
set((state) => {
|
||||
state.assets = state.assets.filter(a => a.modelUuid !== modelUuid);
|
||||
});
|
||||
},
|
||||
|
||||
updateAsset: (modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
Object.assign(asset, updates);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setAssets: (assets) => {
|
||||
set((state) => {
|
||||
state.assets = assets;
|
||||
});
|
||||
},
|
||||
|
||||
// Asset properties
|
||||
setName: (modelUuid, newName) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.modelName = newName;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setPosition: (modelUuid, position) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.position = position;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setRotation: (modelUuid, rotation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.rotation = rotation;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setLock: (modelUuid, isLocked) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isLocked = isLocked;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setCollision: (modelUuid, isCollidable) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isCollidable = isCollidable;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setVisibility: (modelUuid, isVisible) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isVisible = isVisible;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setOpacity: (modelUuid, opacity) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.opacity = opacity;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Animation controls
|
||||
setAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
if (!asset.animationState) {
|
||||
asset.animationState = { current: animation, playing: false };
|
||||
} else {
|
||||
asset.animationState.current = animation;
|
||||
// Asset CRUD operations
|
||||
addAsset: (asset) => {
|
||||
set((state) => {
|
||||
if (!state.assets.some(a => a.modelUuid === asset.modelUuid)) {
|
||||
state.assets.push(asset);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
setCurrentAnimation: (modelUuid, current, isPlaying) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.animationState) {
|
||||
asset.animationState.current = current;
|
||||
asset.animationState.playing = isPlaying;
|
||||
}
|
||||
});
|
||||
},
|
||||
removeAsset: (modelUuid) => {
|
||||
set((state) => {
|
||||
state.assets = state.assets.filter(a => a.modelUuid !== modelUuid);
|
||||
});
|
||||
},
|
||||
|
||||
addAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
if (!asset.animations) {
|
||||
asset.animations = [animation];
|
||||
} else if (!asset.animations.includes(animation)) {
|
||||
asset.animations.push(animation);
|
||||
updateAsset: (modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
Object.assign(asset, updates);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
removeAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.animations) {
|
||||
asset.animations = asset.animations.filter(a => a !== animation);
|
||||
if (asset.animationState?.current === animation) {
|
||||
asset.animationState.playing = false;
|
||||
asset.animationState.current = '';
|
||||
clearAssets: () => {
|
||||
set((state) => {
|
||||
state.assets = [];
|
||||
});
|
||||
},
|
||||
|
||||
setAssets: (assets) => {
|
||||
set((state) => {
|
||||
state.assets = assets;
|
||||
});
|
||||
},
|
||||
|
||||
// Asset properties
|
||||
setName: (modelUuid, newName) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.modelName = newName;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// Event data operations
|
||||
addEventData: (modelUuid, eventData) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.eventData = eventData;
|
||||
}
|
||||
});
|
||||
},
|
||||
setPosition: (modelUuid, position) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.position = position;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateEventData: (modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.eventData) {
|
||||
asset.eventData = { ...asset.eventData, ...updates };
|
||||
}
|
||||
});
|
||||
},
|
||||
setRotation: (modelUuid, rotation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.rotation = rotation;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeEventData: (modelUuid) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
delete asset.eventData;
|
||||
}
|
||||
});
|
||||
},
|
||||
setLock: (modelUuid, isLocked) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isLocked = isLocked;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Helper functions
|
||||
getAssetById: (modelUuid) => {
|
||||
return get().assets.find(a => a.modelUuid === modelUuid);
|
||||
},
|
||||
setCollision: (modelUuid, isCollidable) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isCollidable = isCollidable;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getAssetByPointUuid: (pointUuid) => {
|
||||
return get().assets.find(asset =>
|
||||
asset.eventData?.point?.uuid === pointUuid ||
|
||||
asset.eventData?.points?.some(p => p.uuid === pointUuid)
|
||||
);
|
||||
},
|
||||
setVisibility: (modelUuid, isVisible) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.isVisible = isVisible;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
hasAsset: (modelUuid) => {
|
||||
return get().assets.some(a => a.modelUuid === modelUuid);
|
||||
}
|
||||
}))
|
||||
);
|
||||
setOpacity: (modelUuid, opacity) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.opacity = opacity;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Animation controls
|
||||
setAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
if (!asset.animationState) {
|
||||
asset.animationState = { current: animation, playing: false };
|
||||
} else {
|
||||
asset.animationState.current = animation;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setCurrentAnimation: (modelUuid, current, isPlaying) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.animationState) {
|
||||
asset.animationState.current = current;
|
||||
asset.animationState.playing = isPlaying;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
if (!asset.animations) {
|
||||
asset.animations = [animation];
|
||||
} else if (!asset.animations.includes(animation)) {
|
||||
asset.animations.push(animation);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeAnimation: (modelUuid, animation) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.animations) {
|
||||
asset.animations = asset.animations.filter(a => a !== animation);
|
||||
if (asset.animationState?.current === animation) {
|
||||
asset.animationState.playing = false;
|
||||
asset.animationState.current = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Event data operations
|
||||
addEventData: (modelUuid, eventData) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
asset.eventData = eventData;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateEventData: (modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset?.eventData) {
|
||||
asset.eventData = { ...asset.eventData, ...updates };
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeEventData: (modelUuid) => {
|
||||
set((state) => {
|
||||
const asset = state.assets.find(a => a.modelUuid === modelUuid);
|
||||
if (asset) {
|
||||
delete asset.eventData;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Helper functions
|
||||
getAssetById: (modelUuid) => {
|
||||
return get().assets.find(a => a.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
getAssetByPointUuid: (pointUuid) => {
|
||||
return get().assets.find(asset =>
|
||||
asset.eventData?.point?.uuid === pointUuid ||
|
||||
asset.eventData?.points?.some(p => p.uuid === pointUuid)
|
||||
);
|
||||
},
|
||||
|
||||
hasAsset: (modelUuid) => {
|
||||
return get().assets.some(a => a.modelUuid === modelUuid);
|
||||
}
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
export type AssetStoreType = ReturnType<typeof createAssetStore>;
|
||||
@@ -13,9 +13,12 @@ interface BuilderState {
|
||||
|
||||
wallThickness: number;
|
||||
wallHeight: number;
|
||||
outsideMaterial: string;
|
||||
insideMaterial: string;
|
||||
|
||||
setWallThickness: (thickness: number) => void;
|
||||
setWallHeight: (height: number) => void;
|
||||
setWallMaterial: (material: string, side: 'inside' | 'outside') => void;
|
||||
|
||||
// Aisle
|
||||
|
||||
@@ -82,19 +85,28 @@ export const useBuilderStore = create<BuilderState>()(
|
||||
|
||||
wallThickness: 0.1,
|
||||
wallHeight: 7,
|
||||
outsideMaterial: 'Default Material',
|
||||
insideMaterial: 'Default Material',
|
||||
|
||||
setWallThickness: (thickness: number) => {
|
||||
set((state) => {
|
||||
state.wallThickness = thickness;
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
setWallHeight: (height: number) => {
|
||||
set((state) => {
|
||||
state.wallHeight = height;
|
||||
})
|
||||
},
|
||||
|
||||
setWallMaterial: (material: string, side: 'inside' | 'outside') => {
|
||||
set((state) => {
|
||||
if (side === 'outside') state.outsideMaterial = material;
|
||||
else state.insideMaterial = material;
|
||||
});
|
||||
},
|
||||
|
||||
// Aisle
|
||||
|
||||
selectedAisle: null,
|
||||
|
||||
76
app/src/store/builder/useVersionHistoryStore.ts
Normal file
76
app/src/store/builder/useVersionHistoryStore.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface VersionHistoryStore {
|
||||
versionHistory: VersionHistory;
|
||||
|
||||
createNewVersion: boolean;
|
||||
|
||||
setCreateNewVersion: (createNewVersion: boolean) => void;
|
||||
|
||||
addVersion: (version: Version) => void;
|
||||
setVersions: (versions: Version[]) => void;
|
||||
clearVersions: () => void;
|
||||
|
||||
setVersionName: (versionId: string, versionName: string) => void;
|
||||
updateVersion: (versionId: string, versionName: string, versionDescription: string) => void;
|
||||
|
||||
getVersionById: (versionId: string) => Version | undefined;
|
||||
}
|
||||
|
||||
export const useVersionHistoryStore = create<VersionHistoryStore>()(
|
||||
immer((set, get) => ({
|
||||
versionHistory: [],
|
||||
selectedVersion: null,
|
||||
createNewVersion: false,
|
||||
|
||||
setCreateNewVersion: (createNewVersion: boolean) => {
|
||||
set((state) => {
|
||||
state.createNewVersion = createNewVersion;
|
||||
})
|
||||
},
|
||||
|
||||
addVersion: (version: Version) => {
|
||||
set((state) => {
|
||||
state.versionHistory.unshift(version);
|
||||
})
|
||||
},
|
||||
|
||||
setVersions: (versions: Version[]) => {
|
||||
set((state) => {
|
||||
state.versionHistory = versions;
|
||||
})
|
||||
},
|
||||
|
||||
clearVersions: () => {
|
||||
set((state) => {
|
||||
state.versionHistory = [];
|
||||
})
|
||||
},
|
||||
|
||||
setVersionName: (versionId: string, versionName: string) => {
|
||||
set((state) => {
|
||||
const version = state.versionHistory.find((v) => v.versionId === versionId);
|
||||
if (version) {
|
||||
version.versionName = versionName;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updateVersion: (versionId: string, versionName: string, versionDescription: string) => {
|
||||
set((state) => {
|
||||
const version = state.versionHistory.find((v) => v.versionId === versionId);
|
||||
if (version) {
|
||||
version.versionName = versionName;
|
||||
version.versionDescription = versionDescription;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getVersionById: (versionId: string) => {
|
||||
return get().versionHistory.find((v) => {
|
||||
return v.versionId === versionId
|
||||
})
|
||||
}
|
||||
}))
|
||||
);
|
||||
@@ -19,6 +19,8 @@ interface WallStore {
|
||||
setLayer: (pointUuid: string, layer: number) => void;
|
||||
|
||||
getWallById: (uuid: string) => Wall | undefined;
|
||||
getWallByPointId: (uuid: string) => Wall | undefined;
|
||||
getWallByPoints: (points: Point[]) => Wall | undefined;
|
||||
getWallPointById: (uuid: string) => Point | undefined;
|
||||
getConnectedPoints: (uuid: string) => Point[];
|
||||
}
|
||||
@@ -135,6 +137,25 @@ export const useWallStore = create<WallStore>()(
|
||||
return get().walls.find(w => w.wallUuid === uuid);
|
||||
},
|
||||
|
||||
getWallByPointId: (uuid) => {
|
||||
for (const wall of get().walls) {
|
||||
if (wall.points.some(p => p.pointUuid === uuid)) {
|
||||
return wall;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getWallByPoints: (point) => {
|
||||
for (const wall of get().walls) {
|
||||
if (((wall.points[0].pointUuid === point[0].pointUuid) || (wall.points[1].pointUuid === point[0].pointUuid)) &&
|
||||
((wall.points[0].pointUuid === point[1].pointUuid) || (wall.points[1].pointUuid === point[1].pointUuid))) {
|
||||
return wall;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getWallPointById: (uuid) => {
|
||||
for (const wall of get().walls) {
|
||||
const point = wall.points.find(p => p.pointUuid === uuid);
|
||||
|
||||
Reference in New Issue
Block a user