Skip to content

Commit e92d5b5

Browse files
committed
fix(app): can't expand workspaces
1 parent 00ec29d commit e92d5b5

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

packages/app/src/pages/layout.tsx

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createSignal,
66
For,
77
Match,
8+
on,
89
onCleanup,
910
onMount,
1011
ParentProps,
@@ -275,12 +276,21 @@ export default function Layout(props: ParentProps) {
275276
return bUpdated - aUpdated
276277
}
277278

278-
function scrollToSession(sessionId: string) {
279+
const [scrollSessionKey, setScrollSessionKey] = createSignal<string | undefined>(undefined)
280+
281+
function scrollToSession(sessionId: string, sessionKey: string) {
279282
if (!scrollContainerRef) return
283+
if (scrollSessionKey() === sessionKey) return
280284
const element = scrollContainerRef.querySelector(`[data-session-id="${sessionId}"]`)
281-
if (element) {
282-
element.scrollIntoView({ block: "nearest", behavior: "smooth" })
285+
if (!element) return
286+
const containerRect = scrollContainerRef.getBoundingClientRect()
287+
const elementRect = element.getBoundingClientRect()
288+
if (elementRect.top >= containerRect.top && elementRect.bottom <= containerRect.bottom) {
289+
setScrollSessionKey(sessionKey)
290+
return
283291
}
292+
setScrollSessionKey(sessionKey)
293+
element.scrollIntoView({ block: "nearest", behavior: "smooth" })
284294
}
285295

286296
const currentProject = createMemo(() => {
@@ -325,9 +335,12 @@ export default function Layout(props: ParentProps) {
325335
createEffect(() => {
326336
if (!pageReady()) return
327337
if (!layoutReady()) return
338+
const projects = layout.projects.list()
328339
for (const [directory, expanded] of Object.entries(store.workspaceExpanded)) {
329-
if (layout.sidebar.workspaces(directory)()) continue
330340
if (!expanded) continue
341+
const project = projects.find((item) => item.worktree === directory || item.sandboxes?.includes(directory))
342+
if (!project) continue
343+
if (layout.sidebar.workspaces(project.worktree)()) continue
331344
setStore("workspaceExpanded", directory, false)
332345
}
333346
})
@@ -533,7 +546,7 @@ export default function Layout(props: ParentProps) {
533546
})
534547
}
535548
navigateToSession(session)
536-
queueMicrotask(() => scrollToSession(session.id))
549+
queueMicrotask(() => scrollToSession(session.id, `${session.directory}:${session.id}`))
537550
}
538551

539552
async function archiveSession(session: Session) {
@@ -721,16 +734,23 @@ export default function Layout(props: ParentProps) {
721734
}
722735
}
723736

724-
createEffect(() => {
725-
if (!pageReady()) return
726-
if (!params.dir || !params.id) return
727-
const directory = base64Decode(params.dir)
728-
const id = params.id
729-
setStore("lastSession", directory, id)
730-
notification.session.markViewed(id)
731-
untrack(() => setStore("workspaceExpanded", directory, (value) => value ?? true))
732-
requestAnimationFrame(() => scrollToSession(id))
733-
})
737+
createEffect(
738+
on(
739+
() => ({ ready: pageReady(), dir: params.dir, id: params.id }),
740+
(value) => {
741+
if (!value.ready) return
742+
const dir = value.dir
743+
const id = value.id
744+
if (!dir || !id) return
745+
const directory = base64Decode(dir)
746+
setStore("lastSession", directory, id)
747+
notification.session.markViewed(id)
748+
untrack(() => setStore("workspaceExpanded", directory, (current) => current ?? true))
749+
requestAnimationFrame(() => scrollToSession(id, `${directory}:${id}`))
750+
},
751+
{ defer: true },
752+
),
753+
)
734754

735755
createEffect(() => {
736756
const project = currentProject()

0 commit comments

Comments
 (0)