Files
Dwinzo_dev/app/src/store/visualization/useZone3DWidgetStore.ts

123 lines
4.1 KiB
TypeScript
Raw Normal View History

import { create } from "zustand";
type WidgetData = {
2025-04-03 19:31:25 +05:30
id: string;
type: string;
position: [number, number, number];
2025-04-04 15:17:38 +05:30
rotation?: [number, number, number];
2025-04-03 19:31:25 +05:30
tempPosition?: [number, number, number];
};
type ZoneWidgetStore = {
2025-04-03 19:31:25 +05:30
zoneWidgetData: Record<string, WidgetData[]>;
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) => void;
addWidget: (zoneId: string, widget: WidgetData) => void;
tempWidget: (zoneId: string, widget: WidgetData) => void;
2025-04-03 19:31:25 +05:30
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) => void;
tempWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) => void;
2025-04-04 15:17:38 +05:30
updateWidgetRotation: (zoneId: string, widgetId: string, newRotation: [number, number, number]) => void;
};
export const useZoneWidgetStore = create<ZoneWidgetStore>((set) => ({
2025-04-03 19:31:25 +05:30
zoneWidgetData: {},
2025-04-04 15:17:38 +05:30
setZoneWidgetData: (zoneId: string, widgets: WidgetData[]) =>
set((state: ZoneWidgetStore) => ({
2025-04-03 19:31:25 +05:30
zoneWidgetData: { ...state.zoneWidgetData, [zoneId]: widgets },
})),
2025-04-04 15:17:38 +05:30
addWidget: (zoneId: string, widget: WidgetData) =>
set((state: ZoneWidgetStore) => ({
2025-04-03 19:31:25 +05:30
zoneWidgetData: {
...state.zoneWidgetData,
2025-04-04 15:17:38 +05:30
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), { ...widget, rotation: widget.rotation || [0, 0, 0] }],
2025-04-03 19:31:25 +05:30
},
})),
tempWidget: (zoneId: string, widget: WidgetData) =>
set((state: ZoneWidgetStore) => ({
zoneWidgetData: {
...state.zoneWidgetData,
[zoneId]: [...(state.zoneWidgetData[zoneId] || []), { ...widget, rotation: widget.rotation || [0, 0, 0] }],
},
})),
2025-04-03 19:31:25 +05:30
2025-04-04 15:17:38 +05:30
updateWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) =>
set((state: ZoneWidgetStore) => {
2025-04-03 19:31:25 +05:30
const widgets = state.zoneWidgetData[zoneId] || [];
return {
zoneWidgetData: {
...state.zoneWidgetData,
2025-04-04 15:17:38 +05:30
[zoneId]: widgets.map((widget: WidgetData) =>
2025-04-03 19:31:25 +05:30
widget.id === widgetId ? { ...widget, position: newPosition } : widget
),
},
};
}),
tempWidgetPosition: (zoneId: string, widgetId: string, newPosition: [number, number, number]) =>
set((state: ZoneWidgetStore) => {
const widgets = state.zoneWidgetData[zoneId] || [];
return {
zoneWidgetData: {
...state.zoneWidgetData,
[zoneId]: widgets.map((widget: WidgetData) =>
widget.id === widgetId ? { ...widget, position: newPosition } : widget
),
},
};
}),
2025-04-04 15:17:38 +05:30
updateWidgetRotation: (zoneId: string, widgetId: string, newRotation: [number, number, number]) =>
set((state: ZoneWidgetStore) => {
const widgets = state.zoneWidgetData[zoneId] || [];
return {
zoneWidgetData: {
...state.zoneWidgetData,
[zoneId]: widgets.map((widget: WidgetData) =>
widget.id === widgetId ? { ...widget, rotation: newRotation } : widget
),
},
};
}),
2025-04-03 19:31:25 +05:30
}));
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 }),
}));
2025-04-04 17:47:15 +05:30
interface EditWidgetOptionsStore {
editWidgetOptions: boolean;
setEditWidgetOptions: (value: boolean) => void;
}
export const useEditWidgetOptionsStore = create<EditWidgetOptionsStore>((set) => ({
editWidgetOptions: false, // Initial state
setEditWidgetOptions: (value: boolean) => set({ editWidgetOptions: value }),
}));