@@ -2,7 +2,6 @@ import { Button } from "@nextui-org/react";
22import { AnimatePresence , motion } from "framer-motion" ;
33import { useMediaQuery } from "react-responsive" ;
44import { useFileSystem } from "@/lib/hooks/use-file-system" ;
5- import { CodeEditorViewRef } from "./views/code-editor-view" ;
65import { EditorContext } from "./providers/editor-context-provider" ;
76import { useContext } from "react" ;
87import { ViewTypeEnum } from "@/lib/views/available-views" ;
@@ -58,8 +57,14 @@ function MenuPanel({ children }: { children?: React.ReactNode }) {
5857 ) ;
5958}
6059
61- export default function NavMenu ( { isMenuOpen } : { isMenuOpen : boolean } ) {
62- const { projectPath, openFilePicker, readFile } = useFileSystem ( ) ;
60+ export default function NavMenu ( {
61+ isMenuOpen,
62+ setIsMenuOpen,
63+ } : {
64+ isMenuOpen : boolean ;
65+ setIsMenuOpen : ( isOpen : boolean ) => void ;
66+ } ) {
67+ const { projectPath, openFile } = useFileSystem ( ) ;
6368
6469 const editorContext = useContext ( EditorContext ) ;
6570
@@ -72,48 +77,39 @@ export default function NavMenu({ isMenuOpen }: { isMenuOpen: boolean }) {
7277 { ! projectPath && (
7378 < div className = "flex w-full flex-wrap justify-center gap-x-1 gap-y-1" >
7479 < Button className = "w-40" > New Project</ Button >
75- < Button
76- className = "w-40"
77- onPress = { ( ) => {
78- openFilePicker ( true ) . then ( ( folderPaths ) => {
79- console . log ( folderPaths ) ;
80- } ) ;
81- } }
82- >
80+ < Button className = "w-40" onPress = { ( ) => { } } >
8381 Open Project
8482 </ Button >
8583 < Button className = "w-40" > Save Project</ Button >
8684 < Button className = "w-40" > New File</ Button >
8785 < Button
8886 className = "w-40"
8987 onPress = { ( ) => {
90- openFilePicker ( false ) . then ( ( filePaths ) => {
91- console . log ( filePaths ) ;
92- const filePath = filePaths [ 0 ] ;
93- // Open the first file
94- readFile ( filePath ) . then ( ( file ) => {
95- console . log ( file ) ;
96- file . text ( ) . then ( ( text ) => {
97- console . log ( "File content:\n" + text ) ;
98- const viewDocument : ViewDocument = {
99- fileContent : text ,
100- filePath : filePath ,
101- } ;
102- const view = new View (
103- ViewTypeEnum . Code ,
104- viewDocument ,
105- ) ;
88+ openFile ( ) . then ( ( file ) => {
89+ console . log ( file ) ;
90+ file ?. text ( ) . then ( ( text ) => {
91+ console . log ( "File content:\n" + text ) ;
92+ const viewDocument : ViewDocument = {
93+ fileContent : text ,
94+ filePath : file . name ,
95+ } ;
96+ const view = new View (
97+ ViewTypeEnum . Code ,
98+ viewDocument ,
99+ ) ;
106100
107- // Notify state update
108- editorContext ?. setViewManager ( ( prev ) => {
109- const newVM = ViewManager . copy ( prev ) ;
110- // Add view to view manager
111- newVM ?. addView ( view ) ;
112- // Set the view as active
113- newVM ?. setActiveView ( view ) ;
114- return newVM ;
115- } ) ;
101+ // Notify state update
102+ editorContext ?. setViewManager ( ( prev ) => {
103+ const newVM = ViewManager . copy ( prev ) ;
104+ newVM ?. clearView ( ) ;
105+ // Add view to view manager
106+ newVM ?. addView ( view ) ;
107+ // Set the view as active
108+ newVM ?. setActiveView ( view ) ;
109+ return newVM ;
116110 } ) ;
111+
112+ setIsMenuOpen ( false ) ;
117113 } ) ;
118114 } ) ;
119115 } }
0 commit comments