Skip to content

Commit

Permalink
feat: track isDragging in app state
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Dec 11, 2023
1 parent 4954cbb commit 841ae12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/demo/app/custom-ui/[...puckPath]/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const Tabs = ({
currentTabRef.current = currentTab;
}, [currentTab]);

useEffect(() => {
if (appState.ui.isDragging && currentTab === 1) {
setCurrentTab(-1);
}
}, [currentTab, appState.ui.isDragging]);

return (
<div
onClick={(e) => e.stopPropagation()}
Expand Down
1 change: 1 addition & 0 deletions packages/core/components/Puck/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const defaultAppState: AppState = {
arrayState: {},
itemSelector: null,
componentList: {},
isDragging: false,
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,11 @@ export function Puck({
onBeforeDragStart={(start) => {
onDragStartOrUpdate(start);
setItemSelector(null);
dispatch({ type: "setUi", ui: { isDragging: true } });
}}
onDragEnd={(droppedItem) => {
setDraggedItem(undefined);
dispatch({ type: "setUi", ui: { isDragging: false } });

// User cancel drag
if (!droppedItem.destination) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export type UiState = {
expanded?: boolean;
}
>;
isDragging: boolean;
};

export type AppState = { data: Data; ui: UiState };

0 comments on commit 841ae12

Please sign in to comment.