3d widget editoption function added.
This commit is contained in:
@@ -12,7 +12,7 @@ export const useSocketStore = create<any>((set: any, get: any) => ({
|
||||
}
|
||||
|
||||
const socket = io(
|
||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}`,
|
||||
`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/Builder`,
|
||||
{
|
||||
reconnection: false,
|
||||
auth: { email, organization },
|
||||
|
||||
@@ -1,33 +1,77 @@
|
||||
|
||||
import { create } from "zustand";
|
||||
|
||||
type WidgetData = {
|
||||
id: string;
|
||||
type: string;
|
||||
position: [number, number, number];
|
||||
id: string;
|
||||
type: string;
|
||||
position: [number, number, number];
|
||||
tempPosition?: [number, number, number];
|
||||
};
|
||||
|
||||
type ZoneWidgetStore = {
|
||||
zoneWidgetData: Record<string, WidgetData[]>;
|
||||
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) => void;
|
||||
addWidget: (zoneId: string, widget: WidgetData) => void;
|
||||
zoneWidgetData: Record<string, WidgetData[]>;
|
||||
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) => void;
|
||||
addWidget: (zoneId: string, widget: WidgetData) => void;
|
||||
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) => void;
|
||||
};
|
||||
|
||||
export const useZoneWidgetStore = create<ZoneWidgetStore>((set) => ({
|
||||
zoneWidgetData: {},
|
||||
|
||||
setZoneWidgetData: (zoneId, widgets) =>
|
||||
set((state) => ({
|
||||
zoneWidgetData: {
|
||||
...state.zoneWidgetData,
|
||||
[zoneId]: widgets,
|
||||
},
|
||||
})),
|
||||
|
||||
addWidget: (zoneId, widget) =>
|
||||
set((state) => ({
|
||||
zoneWidgetData: {
|
||||
...state.zoneWidgetData,
|
||||
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), widget],
|
||||
},
|
||||
})),
|
||||
zoneWidgetData: {},
|
||||
|
||||
setZoneWidgetData: (zoneId, widgets) =>
|
||||
set((state) => ({
|
||||
zoneWidgetData: { ...state.zoneWidgetData, [zoneId]: widgets },
|
||||
})),
|
||||
|
||||
addWidget: (zoneId, widget) =>
|
||||
set((state) => ({
|
||||
zoneWidgetData: {
|
||||
...state.zoneWidgetData,
|
||||
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), widget],
|
||||
},
|
||||
})),
|
||||
|
||||
updateWidgetPosition: (zoneId, widgetId, newPosition) =>
|
||||
set((state) => {
|
||||
const widgets = state.zoneWidgetData[zoneId] || [];
|
||||
return {
|
||||
zoneWidgetData: {
|
||||
...state.zoneWidgetData,
|
||||
[zoneId]: widgets.map((widget) =>
|
||||
widget.id === widgetId ? { ...widget, position: newPosition } : widget
|
||||
),
|
||||
},
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
|
||||
interface RightClickStore {
|
||||
rightClickSelected: string | null;
|
||||
setRightClickSelected: (x: string | null) => void;
|
||||
}
|
||||
|
||||
export const useRightClickSelected = create<RightClickStore>((set) => ({
|
||||
rightClickSelected: null, // Default to null
|
||||
setRightClickSelected: (x) => set({ rightClickSelected: x }),
|
||||
}));
|
||||
|
||||
export const useTopData = create<any>((set: any) => ({
|
||||
top: 0,
|
||||
setTop: (x: any) => set({ top: x }),
|
||||
}));
|
||||
|
||||
export const useLeftData = create<any>((set: any) => ({
|
||||
left: 0,
|
||||
setLeft: (x: any) => set({ left: x }),
|
||||
}));
|
||||
|
||||
interface RightSelectStore {
|
||||
rightSelect: string | null;
|
||||
setRightSelect: (x: string | null) => void;
|
||||
}
|
||||
|
||||
export const useRightSelected = create<RightSelectStore>((set) => ({
|
||||
rightSelect: null, // Default state is null
|
||||
setRightSelect: (x) => set({ rightSelect: x }),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user