Skip to content

Commit

Permalink
Merge pull request #984 from nextcloud/fix/neon_files/browser_view
Browse files Browse the repository at this point in the history
fix(neon_files): empty browser view
  • Loading branch information
Leptopoda authored Oct 19, 2023
2 parents b3812b6 + 5848670 commit 6245160
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 66 deletions.
142 changes: 77 additions & 65 deletions packages/neon/neon_files/lib/widgets/browser_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
@override
Widget build(final BuildContext context) => ResultBuilder<List<WebDavFile>>.behaviorSubject(
stream: widget.bloc.files,
builder: (final context, final files) => StreamBuilder<List<String>>(
builder: (final context, final filesSnapshot) => StreamBuilder<List<String>>(
stream: widget.bloc.path,
builder: (final context, final pathSnapshot) => StreamBuilder<List<FilesTask>>(
stream: widget.filesBloc.tasks,
builder: (final context, final tasksSnapshot) => !pathSnapshot.hasData || !tasksSnapshot.hasData
? const SizedBox()
: BackButtonListener(
builder: (final context, final tasksSnapshot) {
if (!pathSnapshot.hasData || !tasksSnapshot.hasData) {
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 {
final path = pathSnapshot.requireData;
if (path.isNotEmpty) {
Expand All @@ -65,71 +82,66 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
presort: const {
(FilesSortProperty.isFolder, SortBoxOrder.ascending),
},
input: files.data,
builder: (final context, final sorted) => ValueListenableBuilder(
valueListenable: widget.bloc.options.showHiddenFilesOption,
builder: (final context, final showHiddenFiles, final _) {
final uploadingTasks = tasksSnapshot.requireData
.whereType<FilesUploadTask>()
.where(
(final task) =>
sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty,
)
.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],
),
);
}
input: files,
builder: (final context, final sorted) {
final uploadingTasks = tasksSnapshot.requireData
.whereType<FilesUploadTask>()
.where(
(final task) =>
sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty,
)
.toList();

final file = sorted[index - uploadingTasks.length];
if ((widget.mode != FilesBrowserMode.selectDirectory || file.isDirectory) &&
(!file.isHidden || showHiddenFiles)) {
final matchingTask = tasksSnapshot.requireData
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name));
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];
final matchingTask = tasksSnapshot.requireData
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name));

final details = matchingTask != null
? FileDetails.fromTask(
task: matchingTask,
file: file,
)
: FileDetails.fromWebDav(
file: file,
path: widget.bloc.path.value,
);
final details = matchingTask != null
? FileDetails.fromTask(
task: matchingTask,
file: file,
)
: FileDetails.fromWebDav(
file: file,
path: widget.bloc.path.value,
);

return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: details,
);
}

return null;
},
isLoading: files.isLoading,
error: files.error,
onRefresh: widget.bloc.refresh,
topScrollingChildren: [
FilesBrowserNavigator(
path: pathSnapshot.requireData,
bloc: widget.bloc,
),
],
);
},
),
return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: details,
mode: widget.mode,
);
},
isLoading: filesSnapshot.isLoading,
error: filesSnapshot.error,
onRefresh: widget.bloc.refresh,
topScrollingChildren: [
FilesBrowserNavigator(
path: pathSnapshot.requireData,
bloc: widget.bloc,
),
],
);
},
),
),
);
},
);
},
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/neon/neon_files/lib/widgets/file_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class FileListTile extends StatelessWidget {
details: details,
bloc: bloc,
),
trailing: !details.hasTask && mode != FilesBrowserMode.noActions
trailing: !details.hasTask && mode == FilesBrowserMode.browser
? FileActions(details: details)
: const SizedBox.square(
dimension: largeIconSize,
Expand Down

0 comments on commit 6245160

Please sign in to comment.