Skip to content

Commit 052f4a3

Browse files
Merge pull request #221 from Saifullah-dev/220-fix/rename-action
fix(rename): prevent state mutation when renaming files
2 parents a741780 + c2a3aa6 commit 052f4a3

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

backend/Readme.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# 📂 File Manager Backend
22

3-
This backend provides a RESTful API for managing files and folders, intended to be used with a front-end file manager component. It allows users to perform various operations such as creating folders, uploading files, renaming, moving, copying, deleting, and downloading files. All APIs are documented using **Swagger**.
3+
This backend provides a RESTful API for managing files and folders, intended to be used with a
4+
front-end file manager component. It allows users to perform various operations such as creating
5+
folders, uploading files, renaming, moving, copying, deleting, and downloading files. All APIs are
6+
documented using **Swagger**.
47

58
## 🚀 Getting Started
69

@@ -40,24 +43,36 @@ Make sure you have the following installed:
4043
npm run devStart
4144
```
4245

46+
- This uses **nodemon**, so it will automatically restart the server whenever you make code
47+
changes.
48+
- ⚠️ If you are testing the **file rename** functionality, use the following instead to avoid
49+
rename permission related issues:
50+
51+
```bash
52+
npm run start
53+
```
54+
4355
This will start the backend server on `http://localhost:3000`.
4456

4557
### ![swagger-icon](https://github.com/user-attachments/assets/9cb14fef-febc-4b52-873c-52dfc80e601e) API Documentation
4658

47-
The API documentation is generated through **Swagger** and can be viewed [here](https://app.swaggerhub.com/apis-docs/SaifullahZubair/file-system_api/1.0.0).
59+
The API documentation is generated through **Swagger** and can be viewed
60+
[here](https://app.swaggerhub.com/apis-docs/SaifullahZubair/file-system_api/1.0.0).
4861

4962
1. To Generate the Swagger docs:
5063

5164
```bash
5265
npm run genDocs
5366
```
5467

55-
2. Access the Swagger documentation:
56-
Open [http://localhost:3000/api-docs/](http://localhost:3000/api-docs/) in your browser to see all available API endpoints and their details.
68+
2. Access the Swagger documentation: Open
69+
[http://localhost:3000/api-docs/](http://localhost:3000/api-docs/) in your browser to see all
70+
available API endpoints and their details.
5771

5872
### ![postman-icon](https://github.com/user-attachments/assets/b0bd6b21-056e-4934-a4d6-b8dc6f7fd6d5) Postman Collection
5973

60-
You can download and use the Postman collection from [here](https://github.com/user-attachments/files/17149486/File.Management.API.postman_collection.json).
74+
You can download and use the Postman collection from
75+
[here](https://github.com/user-attachments/files/17149486/File.Management.API.postman_collection.json).
6176

6277
## 🔧 API Endpoints
6378

@@ -72,7 +87,8 @@ The backend supports the following file system operations:
7287
- **✏️ Rename a File or Folder**: `/rename`
7388
- **🗑️ Delete File(s) or Folder(s)**: `/`
7489

75-
Refer to the [Swagger Documentation](http://localhost:3000/api-docs/) for detailed request/response formats.
90+
Refer to the [Swagger Documentation](http://localhost:3000/api-docs/) for detailed request/response
91+
formats.
7692

7793
## 🗂️ Folder Structure
7894

@@ -110,7 +126,8 @@ backend/
110126
111127
### 📁 Uploads and Folder Creation
112128
113-
- All uploaded files and folders created through the API are placed in the `/public/uploads/` directory. Ensure this directory has the appropriate permissions set to allow file storage.
129+
- All uploaded files and folders created through the API are placed in the `/public/uploads/`
130+
directory. Ensure this directory has the appropriate permissions set to allow file storage.
114131
115132
## ⚠️ Error Handling
116133

frontend/src/FileManager/FileList/useFileList.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,23 @@ const useFileList = (onRefresh, enableFilePreview, triggerAction, permissions, o
208208

209209
const handleItemRenaming = () => {
210210
setCurrentPathFiles((prev) => {
211-
if (prev[selectedFileIndexes.at(-1)]) {
212-
prev[selectedFileIndexes.at(-1)].isEditing = true;
213-
} else {
211+
const lastFileIndex = selectedFileIndexes.at(-1);
212+
213+
if (!prev[lastFileIndex]) {
214214
triggerAction.close();
215+
return prev;
215216
}
216-
return prev;
217+
218+
return prev.map((file, index) => {
219+
if (index === lastFileIndex) {
220+
return {
221+
...file,
222+
isEditing: true,
223+
};
224+
}
225+
226+
return file;
227+
});
217228
});
218229

219230
setSelectedFileIndexes([]);

0 commit comments

Comments
 (0)