Skip to content

Commit a219615

Browse files
committed
fix(app): opened tabs follow created session
1 parent af06175 commit a219615

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/app/src/components/prompt-input.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,10 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
12201220
})
12211221
return undefined
12221222
})
1223-
if (session) navigate(`/${base64Encode(sessionDirectory)}/session/${session.id}`)
1223+
if (session) {
1224+
layout.handoff.setTabs(base64Encode(sessionDirectory), session.id)
1225+
navigate(`/${base64Encode(sessionDirectory)}/session/${session.id}`)
1226+
}
12241227
}
12251228
if (!session) return
12261229

packages/app/src/context/layout.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ type SessionView = {
3535
reviewOpen?: string[]
3636
}
3737

38+
type TabHandoff = {
39+
dir: string
40+
id: string
41+
at: number
42+
}
43+
3844
export type LocalProject = Partial<Project> & { worktree: string; expanded: boolean }
3945

4046
export type ReviewDiffStyle = "unified" | "split"
@@ -115,6 +121,9 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
115121
},
116122
sessionTabs: {} as Record<string, SessionTabs>,
117123
sessionView: {} as Record<string, SessionView>,
124+
handoff: {
125+
tabs: undefined as TabHandoff | undefined,
126+
},
118127
}),
119128
)
120129

@@ -411,6 +420,16 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
411420

412421
return {
413422
ready,
423+
handoff: {
424+
tabs: createMemo(() => store.handoff?.tabs),
425+
setTabs(dir: string, id: string) {
426+
setStore("handoff", "tabs", { dir, id, at: Date.now() })
427+
},
428+
clearTabs() {
429+
if (!store.handoff?.tabs) return
430+
setStore("handoff", "tabs", undefined)
431+
},
432+
},
414433
projects: {
415434
list,
416435
open(directory: string) {

packages/app/src/pages/session.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,47 @@ export default function Page() {
280280
.finally(() => setUi("responding", false))
281281
}
282282
const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
283+
const workspaceKey = createMemo(() => params.dir ?? "")
284+
const workspaceTabs = createMemo(() => layout.tabs(workspaceKey))
283285
const tabs = createMemo(() => layout.tabs(sessionKey))
284286
const view = createMemo(() => layout.view(sessionKey))
285287

288+
createEffect(
289+
on(
290+
() => params.id,
291+
(id, prev) => {
292+
if (!id) return
293+
if (prev) return
294+
295+
const pending = layout.handoff.tabs()
296+
if (!pending) return
297+
if (Date.now() - pending.at > 60_000) {
298+
layout.handoff.clearTabs()
299+
return
300+
}
301+
302+
if (pending.id !== id) return
303+
layout.handoff.clearTabs()
304+
if (pending.dir !== (params.dir ?? "")) return
305+
306+
const from = workspaceTabs().tabs()
307+
if (from.all.length === 0 && !from.active) return
308+
309+
const current = tabs().tabs()
310+
if (current.all.length > 0 || current.active) return
311+
312+
const all = normalizeTabs(from.all)
313+
const active = from.active ? normalizeTab(from.active) : undefined
314+
tabs().setAll(all)
315+
tabs().setActive(active && all.includes(active) ? active : all[0])
316+
317+
workspaceTabs().setAll([])
318+
workspaceTabs().setActive(undefined)
319+
},
320+
{ defer: true },
321+
),
322+
)
323+
286324
if (import.meta.env.DEV) {
287325
createEffect(
288326
on(

0 commit comments

Comments
 (0)