nested folder structures

This commit is contained in:
Leon Bösche
2025-12-17 00:27:47 +01:00
parent d3adefe70b
commit 04877d1727
4 changed files with 37 additions and 11 deletions

View File

@@ -41,7 +41,7 @@ class FileBrowserBloc extends Bloc<FileBrowserEvent, FileBrowserState> {
_filteredFiles = _currentFiles; _filteredFiles = _currentFiles;
_currentPage = 1; _currentPage = 1;
if (files.isEmpty) { if (files.isEmpty) {
emit(DirectoryEmpty()); emit(DirectoryEmpty(_currentPath));
} else { } else {
_emitLoadedState(emit); _emitLoadedState(emit);
} }
@@ -135,7 +135,7 @@ class FileBrowserBloc extends Bloc<FileBrowserEvent, FileBrowserState> {
_filteredFiles = files; _filteredFiles = files;
_currentPage = 1; _currentPage = 1;
if (files.isEmpty) { if (files.isEmpty) {
emit(DirectoryEmpty()); emit(DirectoryEmpty(_currentPath));
} else { } else {
_emitLoadedState(emit); _emitLoadedState(emit);
} }

View File

@@ -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<Object> get props => [currentPath];
}
class DirectoryError extends FileBrowserState { class DirectoryError extends FileBrowserState {
final String error; final String error;

View File

@@ -425,7 +425,7 @@ class _FileExplorerState extends State<FileExplorer> {
context.read<FileBrowserBloc>().add( context.read<FileBrowserBloc>().add(
CreateFolder( CreateFolder(
orgId: 'org1', orgId: 'org1',
parentPath: '/', parentPath: state.currentPath,
folderName: folderName, folderName: folderName,
), ),
); );
@@ -456,8 +456,21 @@ class _FileExplorerState extends State<FileExplorer> {
splashColor: Colors.transparent, splashColor: Colors.transparent,
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
onPressed: () { onPressed: () {
final parentPath = state.currentPath == '/'
? '/'
: state.currentPath
.substring(
0,
state.currentPath.lastIndexOf('/'),
)
.isEmpty
? '/'
: state.currentPath.substring(
0,
state.currentPath.lastIndexOf('/'),
);
context.read<FileBrowserBloc>().add( context.read<FileBrowserBloc>().add(
LoadDirectory(orgId: 'org1', path: '/'), LoadDirectory(orgId: 'org1', path: parentPath),
); );
}, },
), ),
@@ -519,7 +532,7 @@ class _FileExplorerState extends State<FileExplorer> {
); );
}, },
child: Text( child: Text(
'${breadcrumb.name}/', '/${breadcrumb.name}',
style: const TextStyle( style: const TextStyle(
color: AppTheme.secondaryText, color: AppTheme.secondaryText,
), ),

View File

@@ -172,10 +172,11 @@ class MockFileRepository implements FileRepository {
Future<List<FileItem>> getFiles(String orgId, String path) async { Future<List<FileItem>> getFiles(String orgId, String path) async {
await Future.delayed(const Duration(seconds: 1)); await Future.delayed(const Duration(seconds: 1));
if (path == '/') { if (path == '/') {
return _files; return _files.where((f) => !f.path.substring(1).contains('/')).toList();
} else { } else {
// For subfolders, return empty for simplicity return _files
return []; .where((f) => f.path.startsWith('$path/') && f.path != path)
.toList();
} }
} }
@@ -205,10 +206,15 @@ class MockFileRepository implements FileRepository {
String folderName, String folderName,
) async { ) async {
await Future.delayed(const Duration(seconds: 1)); 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( _files.add(
FileItem( FileItem(
name: folderName, name: normalizedName,
path: newPath, path: newPath,
type: FileType.folder, type: FileType.folder,
lastModified: DateTime.now(), lastModified: DateTime.now(),