@@ -12,15 +12,15 @@ import { CodeEditorAgent } from "@/lib/agent/code-editor-agent";
1212import { BaseTTS , getModelTTS } from "@/lib/tts/tts" ;
1313import AgentChatTerminalView from "@/components/views/agent-chat-terminal-view" ;
1414import { AnimatePresence , motion } from "framer-motion" ;
15- import { ViewRef } from "@/lib/types" ;
15+ import { ViewDocument , ViewRef } from "@/lib/types" ;
1616import EditorToolbar from "@/components/editor-toolbar" ;
1717import { getPlatform } from "@/lib/platforms/platform-checker" ;
1818import { EditorContext } from "@/components/providers/editor-context-provider" ;
1919
2020export default function Home ( ) {
2121 const [ isCanvasReady , setIsCanvasReady ] = useState ( false ) ;
2222
23- const viewMap = useRef < Map < string , ViewRef | null > > ( new Map ( ) ) ;
23+ // const viewMap = useRef<Map<string, ViewRef | null>>(new Map());
2424 const editorContext = useContext ( EditorContext ) ;
2525
2626 const sttModelRef = useRef < BaseSTT | undefined > ( undefined ) ;
@@ -61,7 +61,7 @@ export default function Home() {
6161 llmModelRef . current ,
6262 ttsModelRef . current ,
6363 ) ;
64- const codeEditor = viewMap . current . get ( "1" ) as CodeEditorViewRef ;
64+ const codeEditor = editorContext ?. getViewById ( "1" ) as CodeEditorViewRef ;
6565 const viewDocument = codeEditor ?. getViewDocument ( ) ;
6666 editorContext ?. setEditorStates ( ( prev ) => ( {
6767 ...prev ,
@@ -84,7 +84,9 @@ export default function Home() {
8484 } ) ) ;
8585
8686 // Apply changes
87- const codeEditor = viewMap . current . get ( "1" ) as CodeEditorViewRef ;
87+ const codeEditor = editorContext ?. getViewById (
88+ "1" ,
89+ ) as CodeEditorViewRef ;
8890 codeEditor ?. applyChanges ( changes ) ;
8991
9092 // Play the audio in the blob
@@ -182,6 +184,31 @@ export default function Home() {
182184 }
183185 } , [ editorContext ?. editorStates , vad ] ) ;
184186
187+ useEffect ( ( ) => {
188+ const url = "/test.tsx" ;
189+ if ( url ) {
190+ fetch ( url )
191+ . then ( ( res ) => res . text ( ) )
192+ . then ( ( text ) => {
193+ const viewId = "1" ;
194+
195+ // Init a new viewDocument
196+ const viewDocument : ViewDocument = {
197+ fileContent : text ,
198+ filePath : url ,
199+ } ;
200+
201+ // Get the code editor view
202+ const codeEditor = editorContext ?. getViewById (
203+ viewId ,
204+ ) as CodeEditorViewRef ;
205+
206+ // Set the viewDocument
207+ codeEditor ?. setViewDocument ( viewDocument ) ;
208+ } ) ;
209+ }
210+ } , [ ] ) ;
211+
185212 return (
186213 < div className = "flex h-full w-full flex-col" >
187214 < EditorToolbar />
@@ -192,16 +219,17 @@ export default function Home() {
192219 className = { `min-h-0 w-full flex-grow` }
193220 style = { {
194221 cursor :
195- editorContext ?. editorStates ?. isDrawing && ! isCanvasReady ? "wait" : "auto" ,
222+ editorContext ?. editorStates ?. isDrawing && ! isCanvasReady
223+ ? "wait"
224+ : "auto" ,
196225 } }
197226 >
198227 < CodeEditorView
199228 ref = { ( ref ) => {
200- viewMap . current . set ( "1" , ref ) ;
229+ if ( ref ) editorContext ?. addView ( "1" , ref ) ;
201230 } }
202231 width = "100%"
203232 height = "100%"
204- url = "/test.tsx"
205233 isDrawingMode = { editorContext ?. editorStates ?. isDrawing }
206234 isDownloadClip = { editorContext ?. editorStates ?. isDownloadClip }
207235 isDrawHulls = { editorContext ?. editorStates ?. isDrawHulls }
@@ -219,9 +247,8 @@ export default function Home() {
219247 >
220248 < AgentChatTerminalView
221249 ref = { ( ref ) => {
222- viewMap . current . set ( "2" , ref ) ;
250+ if ( ref ) editorContext ?. addView ( "2" , ref ) ;
223251 } }
224- viewMap = { viewMap }
225252 />
226253 </ motion . div >
227254 ) }
0 commit comments