A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.9 KiB

part of '../neon_files.dart';
2 years ago
abstract interface class FilesBrowserBlocEvents {
2 years ago
void setPath(final List<String> path);
void createFolder(final List<String> path);
}
abstract interface class FilesBrowserBlocStates {
2 years ago
BehaviorSubject<Result<List<WebDavFile>>> get files;
BehaviorSubject<List<String>> get path;
}
class FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBlocEvents, FilesBrowserBlocStates {
2 years ago
FilesBrowserBloc(
this.options,
this.account, {
final List<String>? initialPath,
}) {
if (initialPath != null) {
path.add(initialPath);
}
unawaited(refresh());
2 years ago
}
final FilesAppSpecificOptions options;
final Account account;
2 years ago
@override
void dispose() {
unawaited(files.close());
unawaited(path.close());
2 years ago
super.dispose();
}
@override
BehaviorSubject<Result<List<WebDavFile>>> files = BehaviorSubject<Result<List<WebDavFile>>>();
@override
BehaviorSubject<List<String>> path = BehaviorSubject<List<String>>.seeded([]);
@override
Future<void> refresh() async {
await RequestManager.instance.wrapWebDav<List<WebDavFile>>(
account.id,
'files-${path.value.join('/')}',
files,
() async => account.client.webdav.propfind(
Uri(pathSegments: path.value),
prop: WebDavPropWithoutValues.fromBools(
davgetcontenttype: true,
davgetetag: true,
davgetlastmodified: true,
nchaspreview: true,
ocsize: true,
ocfavorite: true,
),
depth: WebDavDepth.one,
),
(final response) => response.toWebDavFiles().sublist(1),
emitEmptyCache: true,
);
}
2 years ago
@override
void setPath(final List<String> p) {
path.add(p);
unawaited(refresh());
}
2 years ago
@override
void createFolder(final List<String> path) {
wrapAction(() async => account.client.webdav.mkcol(Uri(pathSegments: path)));
}
2 years ago
}