@@ -25,7 +25,7 @@ import {
2525 StyledSidebarEntry ,
2626 StyledSidebarEntryMenu ,
2727} from "./Explorer.styles" ;
28- import { MenuButtonStroke } from "../Button/Button " ;
28+ import { MenuButtonStroke } from "Components " ;
2929
3030function getParentDir ( file : Entry ) {
3131 // Check if is a directory and if not get the parent directory of the file
@@ -55,7 +55,7 @@ const Explorer = ({
5555 const [ deleteEntry , setDeleteEntry ] = useState < Entry | undefined > ( undefined ) ;
5656 const [ renameEntry , setRenameEntry ] = useState < Entry | undefined > ( undefined ) ;
5757 const [ selectedEntry , setSelectedEntry ] = useState < Entry | undefined > (
58- undefined ,
58+ undefined
5959 ) ;
6060 const [ selectedLocation , setSelectedLocation ] = useState ( "" ) ;
6161
@@ -105,6 +105,23 @@ const Explorer = ({
105105 }
106106 } ;
107107
108+ const inFileList = ( list : Entry [ ] , file ?: Entry ) => {
109+ if ( file === undefined ) {
110+ return false
111+ }
112+
113+ for ( const entry of list ) {
114+ if ( entry === file ) {
115+ return true ;
116+ }
117+ if ( entry . is_dir ) {
118+ if ( inFileList ( entry . files , file ) ) {
119+ return true ;
120+ }
121+ }
122+ }
123+ } ;
124+
108125 ///////////////// CREATE FILES ///////////////////////////////////////////////
109126
110127 const handleCreateFile = ( file ?: Entry ) => {
@@ -188,7 +205,9 @@ const Explorer = ({
188205 const handleDeleteCurrentFile = ( ) => {
189206 //currentFile === Absolute File path
190207 if ( currentFile ) {
208+ if ( inFileList ( fileList , currentFile ) ) {
191209 handleDeleteModal ( currentFile , false ) ;
210+ }
192211 } else {
193212 warning ( "No file is currently selected." ) ;
194213 }
@@ -212,7 +231,7 @@ const Explorer = ({
212231
213232 const handleCreateFolderSubmit = async (
214233 location : string ,
215- folder_name : string ,
234+ folder_name : string
216235 ) => {
217236 if ( folder_name !== "" ) {
218237 try {
@@ -276,7 +295,9 @@ const Explorer = ({
276295
277296 const handleRenameCurrentFile = async ( ) => {
278297 if ( currentFile ) {
279- handleRename ( currentFile ) ;
298+ if ( inFileList ( fileList , currentFile ) ) {
299+ handleRename ( currentFile ) ;
300+ }
280301 } else {
281302 warning ( "No file is currently selected." ) ;
282303 }
0 commit comments