Skip to content

Commit 39b79db

Browse files
committed
feature(web): thread details card starts closed on new threads
The inline thread details card (workspace, open-in, project scripts, git) opened on every thread with room for it, and only a closed card was remembered, so each new chat showed it again until dismissed. Threads now start with the card closed and remember the ones where it was opened, including across reloads. Persisted state flips accordingly: open cards are stored, closed is the default. An open popover that gains room to sit inline (a wider window) now becomes an open inline card instead of disappearing, matching how closing the right panel already promotes it.
1 parent 6f75bcb commit 39b79db

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

‎apps/web/src/components/chat/ThreadDetailsCard.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function ThreadDetailsCard({
8383
useLayoutEffect(() => {
8484
onPresentationChange(mode);
8585
if (mode === "inline" && popoverOpen)
86-
useRightPanelStore.getState().setThreadPanelOpen(threadRef, "popover", false);
86+
useRightPanelStore.getState().promoteThreadPanelPopover(threadRef);
8787
}, [mode, onPresentationChange, threadRef, popoverOpen]);
8888
useLayoutEffect(() => {
8989
const element = contentElement;

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,22 @@ describe("rightPanelStore", () => {
671671
});
672672
});
673673

674-
it("persists inline preference without restoring an open popover", () => {
674+
it("starts thread details closed and remembers the threads where it was opened", async () => {
675+
const visibility = (ref: typeof refA) =>
676+
selectThreadPanelVisibility(
677+
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
678+
ref,
679+
);
680+
expect(visibility(refA)).toEqual({ inlineOpen: false, popoverOpen: false });
681+
682+
useRightPanelStore.getState().toggleThreadPanel(refA, "inline");
683+
await reloadRightPanelStore();
684+
685+
expect(visibility(refA)).toEqual({ inlineOpen: true, popoverOpen: false });
686+
expect(visibility(refB)).toEqual({ inlineOpen: false, popoverOpen: false });
687+
});
688+
689+
it("persists an opened inline card without restoring an open popover", () => {
675690
expect(
676691
migratePersistedRightPanelState({
677692
threadPanelVisibilityByThreadKey: {
@@ -682,7 +697,7 @@ describe("rightPanelStore", () => {
682697
).toEqual({
683698
byThreadKey: {},
684699
threadPanelVisibilityByThreadKey: {
685-
"env-1:thread-A": { inlineOpen: false, popoverOpen: false },
700+
"env-1:thread-B": { inlineOpen: true, popoverOpen: false },
686701
},
687702
});
688703
});
@@ -696,7 +711,24 @@ describe("rightPanelStore", () => {
696711
useRightPanelStore.getState().threadPanelVisibilityByThreadKey,
697712
refA,
698713
),
699-
).toEqual({ inlineOpen: true, popoverOpen: false });
714+
).toEqual({ inlineOpen: false, popoverOpen: false });
715+
});
716+
717+
it("keeps an open popover visible when the card gets room to sit inline", () => {
718+
const store = useRightPanelStore.getState();
719+
store.setThreadPanelOpen(refA, "popover", true);
720+
store.promoteThreadPanelPopover(refA);
721+
store.promoteThreadPanelPopover(refB);
722+
723+
const visibility = useRightPanelStore.getState().threadPanelVisibilityByThreadKey;
724+
expect(selectThreadPanelVisibility(visibility, refA)).toEqual({
725+
inlineOpen: true,
726+
popoverOpen: false,
727+
});
728+
expect(selectThreadPanelVisibility(visibility, refB)).toEqual({
729+
inlineOpen: false,
730+
popoverOpen: false,
731+
});
700732
});
701733

702734
it("keeps an open popover visible by promoting it to inline when the real panel closes", () => {

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ interface RightPanelStoreState {
201201
open: boolean,
202202
) => void;
203203
toggleThreadPanel: (ref: ScopedThreadRef, presentation: ThreadPanelPresentation) => void;
204+
/** The card moved from popover to inline; keep it visible if the popover was open. */
205+
promoteThreadPanelPopover: (ref: ScopedThreadRef) => void;
204206
removeThread: (ref: ScopedThreadRef) => void;
205207
}
206208

@@ -211,7 +213,7 @@ const EMPTY_THREAD_STATE: ThreadRightPanelState = {
211213
};
212214

213215
const DEFAULT_THREAD_PANEL_VISIBILITY: ThreadPanelVisibility = {
214-
inlineOpen: true,
216+
inlineOpen: false,
215217
popoverOpen: false,
216218
};
217219

@@ -343,7 +345,7 @@ const updateThreadPanelVisibilityMap = (
343345
): Record<string, ThreadPanelVisibility> => {
344346
const current = byThreadKey[threadKey] ?? DEFAULT_THREAD_PANEL_VISIBILITY;
345347
const next = updater(current);
346-
if (next.inlineOpen && !next.popoverOpen) {
348+
if (!next.inlineOpen && !next.popoverOpen) {
347349
if (!(threadKey in byThreadKey)) return byThreadKey;
348350
const { [threadKey]: _removed, ...rest } = byThreadKey;
349351
return rest;
@@ -587,8 +589,8 @@ export function migratePersistedRightPanelState(persistedState: unknown): {
587589
persistedState.threadPanelVisibilityByThreadKey as Record<string, unknown>,
588590
).flatMap(([threadKey, value]) => {
589591
if (!value || typeof value !== "object" || !("inlineOpen" in value)) return [];
590-
return value.inlineOpen === false
591-
? [[threadKey, { inlineOpen: false, popoverOpen: false }]]
592+
return value.inlineOpen === true
593+
? [[threadKey, { inlineOpen: true, popoverOpen: false }]]
592594
: [];
593595
}),
594596
)
@@ -1085,6 +1087,15 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
10851087
: { ...visibility, popoverOpen: !visibility.popoverOpen },
10861088
),
10871089
})),
1090+
promoteThreadPanelPopover: (ref) =>
1091+
set((state) => ({
1092+
threadPanelVisibilityByThreadKey: updateThreadPanelVisibilityMap(
1093+
state.threadPanelVisibilityByThreadKey,
1094+
scopedThreadKey(ref),
1095+
(visibility) =>
1096+
visibility.popoverOpen ? { inlineOpen: true, popoverOpen: false } : visibility,
1097+
),
1098+
})),
10881099
removeThread: (ref) =>
10891100
set((state) => {
10901101
const threadKey = scopedThreadKey(ref);
@@ -1126,7 +1137,7 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
11261137
threadPanelVisibilityByThreadKey: Object.fromEntries(
11271138
Object.entries(state.threadPanelVisibilityByThreadKey).flatMap(
11281139
([threadKey, visibility]) =>
1129-
visibility.inlineOpen ? [] : [[threadKey, { inlineOpen: false, popoverOpen: false }]],
1140+
visibility.inlineOpen ? [[threadKey, { inlineOpen: true, popoverOpen: false }]] : [],
11301141
),
11311142
),
11321143
}),

0 commit comments

Comments
 (0)