Skip to content

Commit 08a075d

Browse files
committed
fix(desktop): better session navigation, hide child sessions
1 parent a2e8737 commit 08a075d

1 file changed

Lines changed: 12 additions & 62 deletions

File tree

‎packages/app/src/pages/layout.tsx‎

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -129,40 +129,18 @@ export default function Layout(props: ParentProps) {
129129
return bUpdated - aUpdated
130130
}
131131

132-
function flattenSessions(sessions: Session[]): Session[] {
133-
const childrenMap = new Map<string, Session[]>()
134-
for (const session of sessions) {
135-
if (session.parentID) {
136-
const children = childrenMap.get(session.parentID) ?? []
137-
children.push(session)
138-
childrenMap.set(session.parentID, children)
139-
}
140-
}
141-
const result: Session[] = []
142-
function visit(session: Session) {
143-
result.push(session)
144-
for (const child of childrenMap.get(session.id) ?? []) {
145-
visit(child)
146-
}
147-
}
148-
for (const session of sessions) {
149-
if (!session.parentID) visit(session)
150-
}
151-
return result
152-
}
153-
154132
function scrollToSession(sessionId: string) {
155133
if (!scrollContainerRef) return
156134
const element = scrollContainerRef.querySelector(`[data-session-id="${sessionId}"]`)
157135
if (element) {
158-
element.scrollIntoView({ block: "center", behavior: "smooth" })
136+
element.scrollIntoView({ block: "nearest", behavior: "smooth" })
159137
}
160138
}
161139

162140
function projectSessions(directory: string) {
163141
if (!directory) return []
164142
const sessions = globalSync.child(directory)[0].session.toSorted(sortSessions)
165-
return flattenSessions(sessions ?? [])
143+
return (sessions ?? []).filter((s) => !s.parentID)
166144
}
167145

168146
const currentSessions = createMemo(() => {
@@ -342,8 +320,11 @@ export default function Layout(props: ParentProps) {
342320
createEffect(() => {
343321
if (!params.dir || !params.id) return
344322
const directory = base64Decode(params.dir)
345-
setStore("lastSession", directory, params.id)
346-
notification.session.markViewed(params.id)
323+
const id = params.id
324+
setStore("lastSession", directory, id)
325+
notification.session.markViewed(id)
326+
layout.projects.expand(directory)
327+
requestAnimationFrame(() => scrollToSession(id))
347328
})
348329

349330
createEffect(() => {
@@ -466,13 +447,9 @@ export default function Layout(props: ParentProps) {
466447
session: Session
467448
slug: string
468449
project: LocalProject
469-
depth?: number
470-
childrenMap: Map<string, Session[]>
471450
mobile?: boolean
472451
}): JSX.Element => {
473452
const notification = useNotification()
474-
const depth = props.depth ?? 0
475-
const children = createMemo(() => props.childrenMap.get(props.session.id) ?? [])
476453
const updated = createMemo(() => DateTime.fromMillis(props.session.time.updated))
477454
const notifications = createMemo(() => notification.session.unseen(props.session.id))
478455
const hasError = createMemo(() => notifications().some((n) => n.type === "error"))
@@ -487,7 +464,7 @@ export default function Layout(props: ParentProps) {
487464
data-session-id={props.session.id}
488465
class="group/session relative w-full pr-2 py-1 rounded-md cursor-default transition-colors
489466
hover:bg-surface-raised-base-hover focus-within:bg-surface-raised-base-hover has-[.active]:bg-surface-raised-base-hover"
490-
style={{ "padding-left": `${16 + depth * 12}px` }}
467+
style={{ "padding-left": "16px" }}
491468
>
492469
<Tooltip placement={props.mobile ? "bottom" : "right"} value={props.session.title} gutter={10}>
493470
<A
@@ -541,18 +518,6 @@ export default function Layout(props: ParentProps) {
541518
</Tooltip>
542519
</div>
543520
</div>
544-
<For each={children()}>
545-
{(child) => (
546-
<SessionItem
547-
session={child}
548-
slug={props.slug}
549-
project={props.project}
550-
depth={depth + 1}
551-
childrenMap={props.childrenMap}
552-
mobile={props.mobile}
553-
/>
554-
)}
555-
</For>
556521
</>
557522
)
558523
}
@@ -565,17 +530,6 @@ export default function Layout(props: ParentProps) {
565530
const [store, setProjectStore] = globalSync.child(props.project.worktree)
566531
const sessions = createMemo(() => store.session.toSorted(sortSessions))
567532
const rootSessions = createMemo(() => sessions().filter((s) => !s.parentID))
568-
const childSessionsByParent = createMemo(() => {
569-
const map = new Map<string, Session[]>()
570-
for (const session of sessions()) {
571-
if (session.parentID) {
572-
const children = map.get(session.parentID) ?? []
573-
children.push(session)
574-
map.set(session.parentID, children)
575-
}
576-
}
577-
return map
578-
})
579533
const hasMoreSessions = createMemo(() => store.session.length >= store.limit)
580534
const loadMoreSessions = async () => {
581535
setProjectStore("limit", (limit) => limit + 5)
@@ -633,13 +587,7 @@ export default function Layout(props: ParentProps) {
633587
<nav class="hidden @[4rem]:flex w-full flex-col gap-1.5">
634588
<For each={rootSessions()}>
635589
{(session) => (
636-
<SessionItem
637-
session={session}
638-
slug={slug()}
639-
project={props.project}
640-
childrenMap={childSessionsByParent()}
641-
mobile={props.mobile}
642-
/>
590+
<SessionItem session={session} slug={slug()} project={props.project} mobile={props.mobile} />
643591
)}
644592
</For>
645593
<Show when={rootSessions().length === 0}>
@@ -761,7 +709,9 @@ export default function Layout(props: ParentProps) {
761709
<DragDropSensors />
762710
<ConstrainDragXAxis />
763711
<div
764-
ref={sidebarProps.mobile ? undefined : scrollContainerRef}
712+
ref={(el) => {
713+
if (!sidebarProps.mobile) scrollContainerRef = el
714+
}}
765715
class="w-full min-w-8 flex flex-col gap-2 min-h-0 overflow-y-auto no-scrollbar"
766716
>
767717
<SortableProvider ids={layout.projects.list().map((p) => p.worktree)}>

0 commit comments

Comments
 (0)