Skip to content

Commit

Permalink
fix: prevent closing navigator when drag and drop on canvas (#4393)
Browse files Browse the repository at this point in the history
Fixes #4158

none is confused with undefined value, replaced it with more explicit
"auto".
  • Loading branch information
TrySound authored Nov 9, 2024
1 parent 4945c8b commit 5509d59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/builder/app/builder/shared/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
name: "clickCanvas",
handler: () => {
$breakpointsMenuView.set(undefined);
setActiveSidebarPanel(undefined);
setActiveSidebarPanel("auto");
},
},

Expand All @@ -124,7 +124,7 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
defaultHotkeys: ["meta+shift+p", "ctrl+shift+p"],
handler: () => {
$isPreviewMode.set($isPreviewMode.get() === false);
setActiveSidebarPanel(undefined);
setActiveSidebarPanel("auto");
},
},
{
Expand Down
7 changes: 5 additions & 2 deletions apps/builder/app/builder/shared/nano-states/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ export const $activeSidebarPanel = computed(
}
);

export const setActiveSidebarPanel = (nextPanel?: SidebarPanelName) => {
/**
* auto shows default panel when sidepanel is undocked and hides when docked
*/
export const setActiveSidebarPanel = (nextPanel: "auto" | SidebarPanelName) => {
const currentPanel = $activeSidebarPanel.get();
// - When navigator is open, user is trying to close the navigator.
// - Navigator is closed, user is trying to close some other panel, and if navigator is undocked, it needs to be opened.
Expand All @@ -114,7 +117,7 @@ export const setActiveSidebarPanel = (nextPanel?: SidebarPanelName) => {
return;
}
}
$activeSidebarPanel_.set(nextPanel);
$activeSidebarPanel_.set(nextPanel === "auto" ? undefined : nextPanel);
};

export const toggleActiveSidebarPanel = (panel: SidebarPanelName) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/builder/sidebar-left/sidebar-left.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
const returnTabRef = useRef<SidebarPanelName | undefined>(undefined);

useSubscribe("dragEnd", () => {
setActiveSidebarPanel("none");
setActiveSidebarPanel("auto");
});

useOnDropEffect(() => {
Expand Down

0 comments on commit 5509d59

Please sign in to comment.