From 04877d1727fa864d2f90024c44bbb934b26cb749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Wed, 17 Dec 2025 00:27:47 +0100 Subject: [PATCH] nested folder structures --- .../blocs/file_browser/file_browser_bloc.dart | 4 ++-- .../file_browser/file_browser_state.dart | 9 ++++++++- b0esche_cloud/lib/pages/file_explorer.dart | 19 ++++++++++++++++--- .../repositories/mock_file_repository.dart | 16 +++++++++++----- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/b0esche_cloud/lib/blocs/file_browser/file_browser_bloc.dart b/b0esche_cloud/lib/blocs/file_browser/file_browser_bloc.dart index 1066f6b..b62c8dc 100644 --- a/b0esche_cloud/lib/blocs/file_browser/file_browser_bloc.dart +++ b/b0esche_cloud/lib/blocs/file_browser/file_browser_bloc.dart @@ -41,7 +41,7 @@ class FileBrowserBloc extends Bloc { _filteredFiles = _currentFiles; _currentPage = 1; if (files.isEmpty) { - emit(DirectoryEmpty()); + emit(DirectoryEmpty(_currentPath)); } else { _emitLoadedState(emit); } @@ -135,7 +135,7 @@ class FileBrowserBloc extends Bloc { _filteredFiles = files; _currentPage = 1; if (files.isEmpty) { - emit(DirectoryEmpty()); + emit(DirectoryEmpty(_currentPath)); } else { _emitLoadedState(emit); } diff --git a/b0esche_cloud/lib/blocs/file_browser/file_browser_state.dart b/b0esche_cloud/lib/blocs/file_browser/file_browser_state.dart index a4a6f5a..8b4cbbc 100644 --- a/b0esche_cloud/lib/blocs/file_browser/file_browser_state.dart +++ b/b0esche_cloud/lib/blocs/file_browser/file_browser_state.dart @@ -62,7 +62,14 @@ class DirectoryLoaded extends FileBrowserState { ]; } -class DirectoryEmpty extends FileBrowserState {} +class DirectoryEmpty extends FileBrowserState { + final String currentPath; + + const DirectoryEmpty(this.currentPath); + + @override + List get props => [currentPath]; +} class DirectoryError extends FileBrowserState { final String error; diff --git a/b0esche_cloud/lib/pages/file_explorer.dart b/b0esche_cloud/lib/pages/file_explorer.dart index 0be65aa..30c2339 100644 --- a/b0esche_cloud/lib/pages/file_explorer.dart +++ b/b0esche_cloud/lib/pages/file_explorer.dart @@ -425,7 +425,7 @@ class _FileExplorerState extends State { context.read().add( CreateFolder( orgId: 'org1', - parentPath: '/', + parentPath: state.currentPath, folderName: folderName, ), ); @@ -456,8 +456,21 @@ class _FileExplorerState extends State { splashColor: Colors.transparent, highlightColor: Colors.transparent, onPressed: () { + final parentPath = state.currentPath == '/' + ? '/' + : state.currentPath + .substring( + 0, + state.currentPath.lastIndexOf('/'), + ) + .isEmpty + ? '/' + : state.currentPath.substring( + 0, + state.currentPath.lastIndexOf('/'), + ); context.read().add( - LoadDirectory(orgId: 'org1', path: '/'), + LoadDirectory(orgId: 'org1', path: parentPath), ); }, ), @@ -519,7 +532,7 @@ class _FileExplorerState extends State { ); }, child: Text( - '${breadcrumb.name}/', + '/${breadcrumb.name}', style: const TextStyle( color: AppTheme.secondaryText, ), diff --git a/b0esche_cloud/lib/repositories/mock_file_repository.dart b/b0esche_cloud/lib/repositories/mock_file_repository.dart index aa906ea..95ab311 100644 --- a/b0esche_cloud/lib/repositories/mock_file_repository.dart +++ b/b0esche_cloud/lib/repositories/mock_file_repository.dart @@ -172,10 +172,11 @@ class MockFileRepository implements FileRepository { Future> getFiles(String orgId, String path) async { await Future.delayed(const Duration(seconds: 1)); if (path == '/') { - return _files; + return _files.where((f) => !f.path.substring(1).contains('/')).toList(); } else { - // For subfolders, return empty for simplicity - return []; + return _files + .where((f) => f.path.startsWith('$path/') && f.path != path) + .toList(); } } @@ -205,10 +206,15 @@ class MockFileRepository implements FileRepository { String folderName, ) async { await Future.delayed(const Duration(seconds: 1)); - final newPath = '$parentPath/$folderName'; + final normalizedName = folderName.startsWith('/') + ? folderName.substring(1) + : folderName; + final newPath = parentPath == '/' + ? '/$normalizedName' + : '$parentPath/$normalizedName'; _files.add( FileItem( - name: folderName, + name: normalizedName, path: newPath, type: FileType.folder, lastModified: DateTime.now(),