Task 2: File Explorer Sidebar
Build a VS Code-style file hierarchy viewer
1. Frontend Structure Expansion
- Add a sidebar
<div>
next to the textarea - Create nested HTML lists (
<ul>
,<li>
) to represent folders/files - Add folder (📁) and file (📄) icons with CSS
2. Backend Command
- Add a new Rust function:
#[tauri::command]
fn get_child_paths(path: String) -> Result<Vec<(String, bool)>, String>- Uses
std::fs::read_dir
to list directory contents - Returns tuples:
(path, is_directory)
- Sorts folders first, then files
- Uses
3. Dynamic Hierarchy Rendering
- Modify "Open File" workflow:
- Get file path via
dialog.open()
- Extract parent directory path
- Call
get_child_paths
to fetch siblings - Render initial file tree in sidebar
- Get file path via
4. Interactive Features
- Add click handlers for:
- Folders: Expand/collapse with ▶/▼ arrows
- Files: Load content into textarea
- Recursive directory loading (fetch children on expand)
5. Security & Error Handling, if needed
- Update
tauri.conf.json
to allow directory traversal:"fs": { "scope": ["$HOME/**"] }
- Handle
Result
errors from Rust in TypeScript
Key Technical Requirements
Component | Technology/Package | Purpose |
---|---|---|
Hierarchy UI | Recursive DOM updates | Dynamic folder expansion |
Backend | std::fs::read_dir | Directory content listing |
State | Event delegation | Handle nested element clicks |
Performance | On-demand loading | Only fetch visible directories |
Conclusion Task 2
You've transformed the basic editor into a file-centric IDE!
"Complexity is just simplicity with layers of intention."
— Next: Add a create new file button! 🚀