@@ -13,12 +13,14 @@ export default function FileBrowser({ sendDataToParent }) {
1313
1414 const [ menuPosition , setMenuPosition ] = useState < { xPos : number ; yPos : number } | null > ( null ) ;
1515 const [ isMenuVisible , setIsMenuVisible ] = useState < boolean > ( false ) ;
16+ const [ contextPath , setContextPath ] = useState < string > ( "" ) ;
1617
17- const handleRightClick = ( event : React . MouseEvent ) => {
18- event . preventDefault ( ) ;
19- setMenuPosition ( { xPos : event . pageX , yPos : event . pageY } ) ;
20- setIsMenuVisible ( true ) ;
21- } ;
18+ // const handleRightClick = (event: React.MouseEvent, path:string) => {
19+ // event.preventDefault();
20+ // setMenuPosition({ xPos: event.pageX, yPos: event.pageY });
21+ // setContextPath(path)
22+ // setIsMenuVisible(true);
23+ // };
2224
2325 const handleCloseMenu = ( ) => {
2426 setIsMenuVisible ( false ) ;
@@ -31,18 +33,19 @@ export default function FileBrowser({ sendDataToParent }) {
3133 const [ cwd , setCwd ] = useState < String > ( "" ) ;
3234
3335
34- const directoryRightClickHandler = ( e ) => {
36+ const directoryRightClickHandler = ( e , path : string ) => {
3537 e . preventDefault ( ) ; // prevent the default behaviour when right clicked
3638 console . log ( "Right Click" ) ;
3739
3840 setMenuPosition ( { xPos : e . pageX , yPos : e . pageY } ) ;
41+ setContextPath ( path ) ;
3942 setIsMenuVisible ( true ) ;
4043 }
4144
4245
4346 const menuItems = [
44- { label : 'Rename' , action : ( ) => alert ( 'Rename' ) } ,
45- { label : 'Delete' , action : ( ) => alert ( 'Delete' ) } ,
47+ { label : 'Rename' , action : ( contextPath : string ) => alert ( 'Rename' + contextPath ) } ,
48+ { label : 'Delete' , action : ( contextPath : string ) => deleteFile ( contextPath ) } ,
4649 ] ;
4750
4851
@@ -91,6 +94,18 @@ export default function FileBrowser({ sendDataToParent }) {
9194 FetchData ( ) ;
9295 }
9396
97+ const deleteFile = async ( path : string ) => {
98+
99+ console . log ( 'Deleting file' ) ;
100+
101+ const res = await fetch ( BaseApiUrl + "/api/contents" , {
102+ method : 'DELETE' ,
103+ body : JSON . stringify ( {
104+ path : path
105+ } )
106+ } ) ;
107+ }
108+
94109 useEffect ( ( ) => {
95110 FetchData ( ) ;
96111 } , [ cwd ] )
@@ -129,6 +144,7 @@ export default function FileBrowser({ sendDataToParent }) {
129144 xPos = { menuPosition . xPos }
130145 yPos = { menuPosition . yPos }
131146 items = { menuItems }
147+ path = { contextPath }
132148 onClose = { handleCloseMenu }
133149 />
134150 ) }
@@ -140,7 +156,7 @@ export default function FileBrowser({ sendDataToParent }) {
140156function FileItem ( { directoryRightClickHandler, handleFileClick, content} ) {
141157 return (
142158 < li className = 'fileItem' >
143- < a onContextMenu = { ( e ) => directoryRightClickHandler ( e ) } onClick = { ( ) => handleFileClick ( content . name , content . path , content . type ) } >
159+ < a onContextMenu = { ( e ) => directoryRightClickHandler ( e , content . path ) } onClick = { ( ) => handleFileClick ( content . name , content . path , content . type ) } >
144160 < img src = "./images/editor/py-icon.svg" alt = "" />
145161 { content . name }
146162 </ a >
@@ -177,7 +193,7 @@ function DirectoryItem({directoryRightClickHandler, data, sendDataToParent}){
177193
178194 return (
179195 < li className = 'fileItem' >
180- < a onContextMenu = { ( e ) => directoryRightClickHandler ( e ) } onClick = { ( ) => handleDirectoryClick ( content . path , content . type ) } >
196+ < a onContextMenu = { ( e ) => directoryRightClickHandler ( e , content . path ) } onClick = { ( ) => handleDirectoryClick ( content . path , content . type ) } >
181197 < img src = "./images/editor/directory.svg" alt = "" />
182198 { content . name }
183199 </ a >
0 commit comments