Browse Source

perf(neon_files): make displaying upload tasks more performant

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/996/head
Nikolas Rimikis 1 year ago
parent
commit
4c6e0042b8
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 38
      packages/neon/neon_files/lib/widgets/browser_view.dart

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

@ -84,28 +84,13 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
}, },
input: files, input: files,
builder: (final context, final sorted) { builder: (final context, final sorted) {
final uploadingTasks = tasksSnapshot.requireData final uploadingTaskTiles = buildUploadTasks(tasksSnapshot.requireData, sorted);
.whereType<FilesUploadTask>()
.where(
(final task) =>
sorted.where((final file) => _pathMatchesFile(task.path, file.name)).isEmpty,
)
.toList();
return NeonListView( return NeonListView(
scrollKey: 'files-${pathSnapshot.requireData.join('/')}', scrollKey: 'files-${pathSnapshot.requireData.join('/')}',
itemCount: uploadingTasks.length + sorted.length, itemCount: sorted.length,
itemBuilder: (final context, final index) { itemBuilder: (final context, final index) {
if (index < uploadingTasks.length) { final file = sorted[index];
return FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: uploadingTasks[index],
),
);
}
final file = sorted[index - uploadingTasks.length];
final matchingTask = tasksSnapshot.requireData final matchingTask = tasksSnapshot.requireData
.firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name)); .firstWhereOrNull((final task) => _pathMatchesFile(task.path, file.name));
@ -134,6 +119,7 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
path: pathSnapshot.requireData, path: pathSnapshot.requireData,
bloc: widget.bloc, bloc: widget.bloc,
), ),
...uploadingTaskTiles,
], ],
); );
}, },
@ -146,6 +132,22 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
), ),
); );
Iterable<Widget> buildUploadTasks(final List<FilesTask> tasks, final List<WebDavFile> files) sync* {
for (final task in tasks) {
if (task is! FilesUploadTask) {
continue;
}
yield FileListTile(
bloc: widget.filesBloc,
browserBloc: widget.bloc,
details: FileDetails.fromUploadTask(
task: task,
),
);
}
}
bool _pathMatchesFile(final List<String> path, final String name) => const ListEquality<String>().equals( bool _pathMatchesFile(final List<String> path, final String name) => const ListEquality<String>().equals(
[...widget.bloc.path.value, name], [...widget.bloc.path.value, name],
path, path,

Loading…
Cancel
Save