From 00392b4556049dfe8b6259a16bdaec5f374aaa57 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 17 Sep 2023 19:34:18 +0200 Subject: [PATCH] refactor(neon_files): Allow setting an intial path for files browser bloc Signed-off-by: jld3103 --- packages/neon/neon_files/lib/blocs/browser.dart | 9 +++++++-- packages/neon/neon_files/lib/blocs/files.dart | 9 ++++++++- packages/neon/neon_files/lib/widgets/actions.dart | 6 ++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/neon/neon_files/lib/blocs/browser.dart b/packages/neon/neon_files/lib/blocs/browser.dart index ca54bb98..b644e9a7 100644 --- a/packages/neon/neon_files/lib/blocs/browser.dart +++ b/packages/neon/neon_files/lib/blocs/browser.dart @@ -15,8 +15,13 @@ abstract interface class FilesBrowserBlocStates { class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents, FilesBrowserBlocStates { FilesBrowserBloc( this.options, - this.account, - ) { + this.account, { + final List? initialPath, + }) { + if (initialPath != null) { + path.add(initialPath); + } + unawaited(refresh()); } diff --git a/packages/neon/neon_files/lib/blocs/files.dart b/packages/neon/neon_files/lib/blocs/files.dart index 56b43d1f..c61f730d 100644 --- a/packages/neon/neon_files/lib/blocs/files.dart +++ b/packages/neon/neon_files/lib/blocs/files.dart @@ -177,7 +177,14 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta tasks.add(tasks.value..remove(task)); } - FilesBrowserBloc getNewFilesBrowserBloc() => FilesBrowserBloc(options, account); + FilesBrowserBloc getNewFilesBrowserBloc({ + final List? initialPath, + }) => + FilesBrowserBloc( + options, + account, + initialPath: initialPath, + ); void _downloadParallelismListener() { _downloadQueue.parallel = options.downloadQueueParallelism.value; diff --git a/packages/neon/neon_files/lib/widgets/actions.dart b/packages/neon/neon_files/lib/widgets/actions.dart index d5727200..73e6646d 100644 --- a/packages/neon/neon_files/lib/widgets/actions.dart +++ b/packages/neon/neon_files/lib/widgets/actions.dart @@ -48,9 +48,8 @@ class FileActions extends StatelessWidget { if (!context.mounted) { return; } - final b = bloc.getNewFilesBrowserBloc(); final originalPath = details.path.sublist(0, details.path.length - 1); - b.setPath(originalPath); + final b = bloc.getNewFilesBrowserBloc(initialPath: originalPath); final result = await showDialog?>( context: context, builder: (final context) => FilesChooseFolderDialog( @@ -67,9 +66,8 @@ class FileActions extends StatelessWidget { if (!context.mounted) { return; } - final b = bloc.getNewFilesBrowserBloc(); final originalPath = details.path.sublist(0, details.path.length - 1); - b.setPath(originalPath); + final b = bloc.getNewFilesBrowserBloc(initialPath: originalPath); final result = await showDialog?>( context: context, builder: (final context) => FilesChooseFolderDialog(