11"use client"
22
3+ import { useMemo } from "react"
34import { useThemeColors , useIsDark } from "@/context/ThemeContext"
45import { FONTS } from "@/lib/constants"
6+ import { readSessionCache } from "@/lib/sessionCache"
7+ import { readLatestSessionUiCache , readSessionUiCache } from "@/lib/sessionUiCache"
8+
9+ function readRouteSessionId ( ) : string {
10+ if ( typeof window === "undefined" ) return ""
11+ try {
12+ return new URLSearchParams ( window . location . search ) . get ( "id" ) ?. trim ( ) || ""
13+ } catch {
14+ return ""
15+ }
16+ }
517
618/**
719 * Shown while the session page is loading (Suspense). Keeps TopBar + content area
@@ -10,12 +22,32 @@ import { FONTS } from "@/lib/constants"
1022export function SessionRouteFallback ( ) {
1123 const COLORS = useThemeColors ( )
1224 const isDark = useIsDark ( )
25+ const sessionId = useMemo ( ( ) => readRouteSessionId ( ) , [ ] )
26+ const cachedUi = useMemo (
27+ ( ) => ( sessionId ? readSessionUiCache ( sessionId ) : null ) ,
28+ [ sessionId ] ,
29+ )
30+ const cachedSession = useMemo (
31+ ( ) => ( sessionId ? readSessionCache ( sessionId ) : null ) ,
32+ [ sessionId ] ,
33+ )
34+ const latestUi = useMemo (
35+ ( ) => ( ! cachedUi ? readLatestSessionUiCache ( ) : null ) ,
36+ [ cachedUi ] ,
37+ )
38+ const fallbackTitle = (
39+ cachedUi ?. title
40+ || cachedSession ?. question
41+ || latestUi ?. entry . title
42+ || "Session"
43+ ) . trim ( ) || "Session"
44+ const fallbackDraft = cachedUi ?. draft ?? latestUi ?. entry . draft ?? ""
1345 const topBarGradient = isDark
1446 ? "linear-gradient(180deg, transparent 0%, rgba(255, 255, 255, 0.02) 50%, rgba(255, 255, 255, 0.08) 100%)"
1547 : "linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.02) 50%, rgba(0, 0, 0, 0.06) 100%)"
1648
1749 return (
18- < div style = { { flex : 1 , minHeight : 0 , display : "flex" , flexDirection : "column" , overflow : "hidden" , background : COLORS . bg } } >
50+ < div style = { { flex : 1 , minHeight : 0 , display : "flex" , flexDirection : "column" , overflow : "hidden" , background : COLORS . bg , position : "relative" } } >
1951 < header
2052 style = { {
2153 height : "60px" ,
@@ -27,10 +59,39 @@ export function SessionRouteFallback() {
2759 } }
2860 >
2961 < span style = { { fontFamily : FONTS . sans , fontSize : "16px" , fontWeight : 600 , color : COLORS . textPrimary } } >
30- Untitled
62+ { fallbackTitle }
3163 </ span >
3264 </ header >
3365 < div style = { { flex : 1 , minHeight : 0 , background : COLORS . bg } } />
66+ < div style = { { position : "absolute" , inset : 0 , display : "flex" , alignItems : "flex-end" , justifyContent : "center" , paddingBottom : "6px" , pointerEvents : "none" , zIndex : 10 } } >
67+ < div
68+ style = { {
69+ width : "720px" ,
70+ maxWidth : "85vw" ,
71+ borderRadius : "24px" ,
72+ border : `1px solid ${ COLORS . border } ` ,
73+ background : isDark ? "#0A0A0A" : COLORS . modalBg ,
74+ padding : "18px 24px" ,
75+ minHeight : "64px" ,
76+ display : "flex" ,
77+ alignItems : "center" ,
78+ } }
79+ >
80+ < span
81+ style = { {
82+ fontFamily : FONTS . sans ,
83+ fontSize : "16px" ,
84+ color : fallbackDraft . trim ( ) ? COLORS . textPrimary : COLORS . textDimmed ,
85+ whiteSpace : "nowrap" ,
86+ overflow : "hidden" ,
87+ textOverflow : "ellipsis" ,
88+ width : "100%" ,
89+ } }
90+ >
91+ { fallbackDraft . trim ( ) ? fallbackDraft : "Add to thread..." }
92+ </ span >
93+ </ div >
94+ </ div >
3495 </ div >
3596 )
3697}
0 commit comments