Browse Source

Merge pull request #984 from nextcloud/fix/neon_files/browser_view

fix(neon_files): empty browser view
pull/988/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
6245160dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 142
      packages/neon/neon_files/lib/widgets/browser_view.dart
  2. 2
      packages/neon/neon_files/lib/widgets/file_list_tile.dart

142
packages/neon/neon_files/lib/widgets/browser_view.dart

@ -43,13 +43,30 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
@override @override
Widget build(final BuildContext context) => ResultBuilder<List<WebDavFile>>.behaviorSubject( Widget build(final BuildContext context) => ResultBuilder<List<WebDavFile>>.behaviorSubject(
stream: widget.bloc.files, stream: widget.bloc.files,
builder: (final context, final files) => StreamBuilder<List<String>>( builder: (final context, final filesSnapshot) => StreamBuilder<List<String>>(
stream: widget.bloc.path, stream: widget.bloc.path,
builder: (final context, final pathSnapshot) => StreamBuilder<List<FilesTask>>( builder: (final context, final pathSnapshot) => StreamBuilder<List<FilesTask>>(
stream: widget.filesBloc.tasks, stream: widget.filesBloc.tasks,
builder: (final context, final tasksSnapshot) => !pathSnapshot.hasData || !tasksSnapshot.hasData builder: (final context, final tasksSnapshot) {
? const SizedBox() if (!pathSnapshot.hasData || !tasksSnapshot.hasData) {
: BackButtonListener( return const SizedBox();
}
return ValueListenableBuilder(
valueListenable: widget.bloc.options.showHiddenFilesOption,
builder: (final context, final showHiddenFiles, final _) {
final files = filesSnapshot.data?.where((final file) {
var hideFile = false;
if (widget.mode == FilesBrowserMode.selectDirectory && !file.isDirectory) {
hideFile = true;
}
if (!showHiddenFiles && file.isHidden) {
hideFile = true;
}
return !hideFile;
}).toList();
return BackButtonListener(
onBackButtonPressed: () async { onBackButtonPressed: () async {
final path = pathSnapshot.requireData; final path = pathSnapshot.requireData;
if (path.isNotEmpty) { if (path.isNotEmpty) {
@ -65,71 +82,66 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
presort: const { presort: const {
(FilesSortProperty.isFolder, SortBoxOrder.ascending), (FilesSortProperty.isFolder, SortBoxOrder.ascending),
}, },
input: files.data, input: files,
builder: (final context, final sorted) => ValueListenableBuilder( builder: (final context, final sorted) {
valueListenable: widget.bloc.options.showHiddenFilesOption, final uploadingTasks = tasksSnapshot.requireData
builder: (final context, final showHiddenFiles, final _) { .whereType<FilesUploadTask>()
final uploadingTasks = tasksSnapshot.requireData .where(
.whereType<FilesUploadTask>() (final task) =>
.where( sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty,
(final task) => )
sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty, .toList();
)
.toList();
return NeonListView(
scrollKey: 'files-${pathSnapshot.requireData.join('/')}',
itemCount: uploadingTasks.length + sorted.length,
itemBuilder: (final context, final index) {
if (index < uploadingTasks.length) {
return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: uploadingTasks[index],
),
);
}
final file = sorted[index - uploadingTasks.length]; return NeonListView(
if ((widget.mode != FilesBrowserMode.selectDirectory || file.isDirectory) && scrollKey: 'files-${pathSnapshot.requireData.join('/')}',
(!file.isHidden || showHiddenFiles)) { itemCount: uploadingTasks.length + sorted.length,
final matchingTask = tasksSnapshot.requireData itemBuilder: (final context, final index) {
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name)); if (index < uploadingTasks.length) {
return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: uploadingTasks[index],
),
);
}
final file = sorted[index - uploadingTasks.length];
final matchingTask = tasksSnapshot.requireData
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name));
final details = matchingTask != null final details = matchingTask != null
? FileDetails.fromTask( ? FileDetails.fromTask(
task: matchingTask, task: matchingTask,
file: file, file: file,
) )
: FileDetails.fromWebDav( : FileDetails.fromWebDav(
file: file, file: file,
path: widget.bloc.path.value, path: widget.bloc.path.value,
); );
return FileListTile( return FileListTile(
bloc: widget.filesBloc, bloc: widget.filesBloc,
browserBloc: widget.bloc, browserBloc: widget.bloc,
details: details, details: details,
); mode: widget.mode,
} );
},
return null; isLoading: filesSnapshot.isLoading,
}, error: filesSnapshot.error,
isLoading: files.isLoading, onRefresh: widget.bloc.refresh,
error: files.error, topScrollingChildren: [
onRefresh: widget.bloc.refresh, FilesBrowserNavigator(
topScrollingChildren: [ path: pathSnapshot.requireData,
FilesBrowserNavigator( bloc: widget.bloc,
path: pathSnapshot.requireData, ),
bloc: widget.bloc, ],
), );
], },
);
},
),
), ),
), );
},
);
},
), ),
), ),
); );

2
packages/neon/neon_files/lib/widgets/file_list_tile.dart

@ -73,7 +73,7 @@ class FileListTile extends StatelessWidget {
details: details, details: details,
bloc: bloc, bloc: bloc,
), ),
trailing: !details.hasTask && mode != FilesBrowserMode.noActions trailing: !details.hasTask && mode == FilesBrowserMode.browser
? FileActions(details: details) ? FileActions(details: details)
: const SizedBox.square( : const SizedBox.square(
dimension: largeIconSize, dimension: largeIconSize,

Loading…
Cancel
Save