@@ -38,58 +38,122 @@ export interface NoteInputHandle {
3838 prepareForTabChange : ( ) => void ;
3939}
4040
41+ type NoteInputProps = {
42+ tab : Extract < Tab , { type : "sessions" } > ;
43+ onNavigateToTitle ?: ( pixelWidth ?: number ) => void ;
44+ onScroll ?: UIEventHandler < HTMLDivElement > ;
45+ editorTabs ?: TabEditorView [ ] ;
46+ currentTab ?: TabEditorView ;
47+ handleTabChange ?: ( view : TabEditorView ) => void ;
48+ hideHeader ?: boolean ;
49+ sessionMode ?: SessionMode ;
50+ } ;
51+
4152export function shouldShowTranscriptTabSpinner ( sessionMode : SessionMode ) {
4253 return sessionMode === "finalizing" || sessionMode === "running_batch" ;
4354}
4455
45- export const NoteInput = forwardRef <
56+ export const NoteInput = forwardRef < NoteInputHandle , NoteInputProps > (
57+ function NoteInput ( props , ref ) {
58+ if (
59+ props . editorTabs &&
60+ props . currentTab &&
61+ props . handleTabChange &&
62+ props . sessionMode !== undefined
63+ ) {
64+ return (
65+ < NoteInputContent
66+ { ...props }
67+ ref = { ref }
68+ editorTabs = { props . editorTabs }
69+ currentTab = { props . currentTab }
70+ commitTabChange = { props . handleTabChange }
71+ sessionMode = { props . sessionMode }
72+ />
73+ ) ;
74+ }
75+
76+ return < NoteInputWithDerivedState { ...props } ref = { ref } /> ;
77+ } ,
78+ ) ;
79+
80+ const NoteInputWithDerivedState = forwardRef < NoteInputHandle , NoteInputProps > (
81+ function NoteInputWithDerivedState (
82+ { tab, editorTabs, currentTab, handleTabChange, ...props } ,
83+ ref ,
84+ ) {
85+ const fallbackEditorTabs = useEditorTabs ( { sessionId : tab . id } ) ;
86+ const fallbackCurrentTab : TabEditorView = useCurrentNoteTab ( tab ) ;
87+ const updateSessionTabState = useTabs (
88+ ( state ) => state . updateSessionTabState ,
89+ ) ;
90+ const tabRef = useRef ( tab ) ;
91+ tabRef . current = tab ;
92+ const sessionMode = useListener ( ( state ) => state . getSessionMode ( tab . id ) ) ;
93+
94+ const commitTabChange = useCallback (
95+ ( tabView : TabEditorView ) => {
96+ if ( handleTabChange ) {
97+ handleTabChange ( tabView ) ;
98+ return ;
99+ }
100+
101+ updateSessionTabState ( tabRef . current , {
102+ ...tabRef . current . state ,
103+ view : tabView ,
104+ } ) ;
105+ } ,
106+ [ handleTabChange , updateSessionTabState ] ,
107+ ) ;
108+
109+ return (
110+ < NoteInputContent
111+ { ...props }
112+ ref = { ref }
113+ tab = { tab }
114+ editorTabs = { editorTabs ?? fallbackEditorTabs }
115+ currentTab = { currentTab ?? fallbackCurrentTab }
116+ commitTabChange = { commitTabChange }
117+ sessionMode = { props . sessionMode ?? sessionMode }
118+ />
119+ ) ;
120+ } ,
121+ ) ;
122+
123+ const NoteInputContent = forwardRef <
46124 NoteInputHandle ,
47- {
48- tab : Extract < Tab , { type : "sessions" } > ;
49- onNavigateToTitle ?: ( pixelWidth ?: number ) => void ;
50- onScroll ?: UIEventHandler < HTMLDivElement > ;
51- editorTabs ?: TabEditorView [ ] ;
52- currentTab ?: TabEditorView ;
53- handleTabChange ?: ( view : TabEditorView ) => void ;
54- hideHeader ?: boolean ;
125+ Omit < NoteInputProps , "editorTabs" | "currentTab" | "handleTabChange" > & {
126+ editorTabs : TabEditorView [ ] ;
127+ currentTab : TabEditorView ;
128+ commitTabChange : ( view : TabEditorView ) => void ;
129+ sessionMode : SessionMode ;
55130 }
56131> (
57132 (
58133 {
59134 tab,
60135 onNavigateToTitle,
61136 onScroll,
62- editorTabs : providedEditorTabs ,
63- currentTab : providedCurrentTab ,
64- handleTabChange : providedHandleTabChange ,
137+ editorTabs,
138+ currentTab,
139+ commitTabChange ,
65140 hideHeader = false ,
141+ sessionMode,
66142 } ,
67143 ref ,
68144 ) => {
69- const fallbackEditorTabs = useEditorTabs ( { sessionId : tab . id } ) ;
70- const updateSessionTabState = useTabs (
71- ( state ) => state . updateSessionTabState ,
72- ) ;
73145 const internalEditorRef = useRef < NoteEditorRef > ( null ) ;
74146 const [ container , setContainer ] = useState < HTMLDivElement | null > ( null ) ;
75147 const [ view , setView ] = useState < EditorView | null > ( null ) ;
76148
77149 const sessionId = tab . id ;
78-
79- const tabRef = useRef ( tab ) ;
80- tabRef . current = tab ;
81-
82- const fallbackCurrentTab : TabEditorView = useCurrentNoteTab ( tab ) ;
83- const editorTabs = providedEditorTabs ?? fallbackEditorTabs ;
84- const currentTab = providedCurrentTab ?? fallbackCurrentTab ;
85150 const deferredCurrentTab = useDeferredValue ( currentTab ) ;
86151 const renderedCurrentTab = editorTabs . some ( ( editorTab ) =>
87152 isSameEditorView ( editorTab , deferredCurrentTab ) ,
88153 )
89154 ? deferredCurrentTab
90155 : currentTab ;
91156
92- const sessionMode = useListener ( ( state ) => state . getSessionMode ( sessionId ) ) ;
93157 const isMeetingInProgress =
94158 sessionMode === "active" ||
95159 sessionMode === "finalizing" ||
@@ -127,22 +191,9 @@ export const NoteInput = forwardRef<
127191 }
128192
129193 onBeforeTabChange ( ) ;
130- if ( providedHandleTabChange ) {
131- providedHandleTabChange ( tabView ) ;
132- } else {
133- updateSessionTabState ( tabRef . current , {
134- ...tabRef . current . state ,
135- view : tabView ,
136- } ) ;
137- }
194+ commitTabChange ( tabView ) ;
138195 } ,
139- [
140- currentTab ,
141- onBeforeTabChange ,
142- providedHandleTabChange ,
143- renderedCurrentTab ,
144- updateSessionTabState ,
145- ] ,
196+ [ commitTabChange , currentTab , onBeforeTabChange , renderedCurrentTab ] ,
146197 ) ;
147198
148199 const handleAdjacentViewShortcut = useCallback (
0 commit comments