Skip to content

Commit b520687

Browse files
committed
fix(panes): close button closes the session instead of just detaching
The pane Close button (X, middle-click, and context-menu item) called layoutStore.closePane, which only popped the leaf out of the split tree — identical to detachPane. The session stayed alive and reappeared as an ungrouped tab. handleClosePane now tears the session down like TitleBar.closeSessionById: multiplayer stopSharing/leaveSession, disconnect() for connected sessions, then removeSession (which also removes the leaf from the layout tree). Removed the now-dead, misleadingly-named closePane store action.
1 parent 6bfe69e commit b520687

2 files changed

Lines changed: 9 additions & 33 deletions

File tree

src/components/panes/PaneHeader.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export function PaneHeader({ paneId, session, active }: { paneId: string; sessio
9797
const [pingEnabled] = useToggle("reachability");
9898
const activePollIntervalMs = useHostPingStore((s) => s.activePollIntervalMs);
9999
const setStatus = useHostPingStore((s) => s.setStatus);
100-
const closePane = useLayoutStore((s) => s.closePane);
101100
const splitPane = useLayoutStore((s) => s.splitPane);
102101
const detachPane = useLayoutStore((s) => s.detachPane);
103102
const maximizedPaneId = useLayoutStore((s) => s.maximizedPaneId);
@@ -246,7 +245,15 @@ export function PaneHeader({ paneId, session, active }: { paneId: string; sessio
246245
};
247246

248247
const handleClosePane = () => {
249-
closePane(paneId);
248+
if (mpState) {
249+
if (mpState.role === "host") useTeamSessionStore.getState().stopSharing(session.id).catch(() => {});
250+
else useTeamSessionStore.getState().leaveSession(session.id);
251+
}
252+
// disconnect() is async; removeSession() drops it synchronously so it can't linger as an ungrouped tab
253+
if (session.type !== "multiplayer" && (session.status === "connected" || session.status === "connecting")) {
254+
void useSessionStore.getState().disconnect(session.id);
255+
}
256+
useSessionStore.getState().removeSession(session.id);
250257
const layout = useLayoutStore.getState();
251258
const nextLeaf = findLeaf(layout.root, layout.activePaneId);
252259
if (nextLeaf) useSessionStore.getState().setActive(nextLeaf.sessionId);

src/stores/layoutStore.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ interface LayoutStore {
5050
splitPane(targetPaneId: string, sessionId: string, position: SplitPosition): void;
5151
movePane(sourcePaneId: string, targetPaneId: string, position: SplitPosition): void;
5252
detachPane(paneId: string): string | null;
53-
closePane(paneId: string): void;
5453
removeSession(sessionId: string): void;
5554
setRatio(splitNodeId: string, ratio: number): void;
5655
setActivePane(paneId: string): void;
@@ -369,36 +368,6 @@ export const useLayoutStore = create<LayoutStore>((set) => ({
369368
return detachedSessionId;
370369
},
371370

372-
closePane: (paneId) => {
373-
set((state) => {
374-
if (!state.root) return {};
375-
const { root } = removeLeaf(state.root, paneId);
376-
if (!root || root.type === "leaf") {
377-
const splitTabs = state.splitTabs.filter((tab) => tab.id !== state.activeSplitTabId);
378-
const nextTab = splitTabs[splitTabs.length - 1] ?? null;
379-
return {
380-
splitTabs,
381-
titlebarOrder: state.titlebarOrder.filter((key) => key !== `split:${state.activeSplitTabId}`),
382-
...fieldsFromTab(nextTab),
383-
};
384-
}
385-
const nextActive = findLeaf(root, state.activePaneId) ?? firstLeaf(root);
386-
return {
387-
...updateActiveSplitTab(state, {
388-
root: root!,
389-
activePaneId: nextActive?.id ?? null,
390-
maximizedPaneId: state.maximizedPaneId === paneId ? null : state.maximizedPaneId,
391-
broadcastActive: root ? state.broadcastActive : false,
392-
}),
393-
root,
394-
activePaneId: nextActive?.id ?? null,
395-
maximizedPaneId: state.maximizedPaneId === paneId ? null : state.maximizedPaneId,
396-
broadcastActive: root ? state.broadcastActive : false,
397-
splitTabActive: root ? state.splitTabActive : false,
398-
};
399-
});
400-
},
401-
402371
removeSession: (sessionId) => {
403372
set((state) => {
404373
const splitTabs = state.splitTabs.flatMap((tab): SplitTab[] => {

0 commit comments

Comments
 (0)