From 20bb8a0dac328f19645a49650105fe8d80930442 Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 19 May 2026 20:26:30 +0800 Subject: [PATCH] fix: show selected session detail beside sidebar --- src/app/page.tsx | 2 +- src/components/Sidebar.tsx | 43 ++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index bfa2af4..0c10e9e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -291,7 +291,7 @@ export default function Home() { onPick={id => setCurrent(sessions.find(s => s.id === id) ?? null)} onNew={() => setCurrent(null)} /> -
+
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 555a225..683369f 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,5 +1,6 @@ 'use client'; +import { useEffect, useRef, useState } from 'react'; import type { GenSession } from '@/lib/types'; function modeLabel(mode?: GenSession['inputMode']) { @@ -87,6 +88,28 @@ export default function Sidebar({ onPick: (id: string) => void; onNew: () => void; }) { + const rootRef = useRef(null); + const rowRefs = useRef>({}); + const [detailTop, setDetailTop] = useState(140); + + const activeSession = sessions.find(session => session.id === currentId) ?? null; + + function syncDetailTop() { + if (!currentId) return; + const row = rowRefs.current[currentId]; + const root = rootRef.current; + if (!row || !root) return; + const rowRect = row.getBoundingClientRect(); + const rootRect = root.getBoundingClientRect(); + const rawTop = rowRect.top - rootRect.top; + const maxTop = Math.max(96, rootRect.height - 360); + setDetailTop(Math.min(Math.max(96, rawTop), maxTop)); + } + + useEffect(() => { + syncDetailTop(); + }, [currentId, sessions.length, open]); + if (!open) { return (