78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
|
|
import { create } from "zustand";
|
|
|
|
type WidgetData = {
|
|
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;
|
|
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],
|
|
},
|
|
})),
|
|
|
|
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 }),
|
|
}));
|