Collapsible folder tree that supports adding new files

In this React-based problem, we are tasked with managing a nested directory structure where each directory can be either opened to reveal its subdirectories or closed to hide them. Additionally, users must be able to add new files to any directory within this structure. This file explorer in React is a tree view, so the ARIA pattern is a useful reference.
The core functionalities required for this application include:
To illustrate, consider the following scenarios:
| Action | Expected Outcome |
|---|---|
| Closing a directory | Its subdirectories should be hidden. |
| Opening a directory | Its subdirectories should be revealed. |
| Adding a new file to a directory | The file should appear in the directory’s list of files. |
This challenge involves a combination of state management, event handling, and dynamic rendering in React, making it a comprehensive task for testing one’s understanding of React fundamentals, especially in the context of handling complex, nested structures.