mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-27 17:34:44 +01:00
Only explicitly query file cache on first run
This commit is contained in:
parent
c9a3a01d85
commit
60353bc489
1 changed files with 11 additions and 7 deletions
|
@ -141,15 +141,20 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
|
|||
|
||||
Stream<ScanDirBlocState> _onEventQuery(ScanDirBlocQuery ev) async* {
|
||||
yield ScanDirBlocLoading(ev.account, state.files);
|
||||
bool hasContent = state.files.isNotEmpty;
|
||||
|
||||
ScanDirBlocState cacheState = ScanDirBlocInit();
|
||||
await for (final s in _queryOffline(ev, () => cacheState)) {
|
||||
cacheState = s;
|
||||
if (!hasContent) {
|
||||
// show something instantly on first load
|
||||
ScanDirBlocState cacheState = ScanDirBlocInit();
|
||||
await for (final s in _queryOffline(ev, () => cacheState)) {
|
||||
cacheState = s;
|
||||
}
|
||||
yield ScanDirBlocLoading(ev.account, cacheState.files);
|
||||
hasContent = cacheState.files.isNotEmpty;
|
||||
}
|
||||
yield ScanDirBlocLoading(ev.account, cacheState.files);
|
||||
|
||||
ScanDirBlocState newState = ScanDirBlocInit();
|
||||
if (cacheState.files.isEmpty) {
|
||||
if (!hasContent) {
|
||||
await for (final s in _queryOnline(ev, () => newState)) {
|
||||
newState = s;
|
||||
yield s;
|
||||
|
@ -161,8 +166,7 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
|
|||
if (newState is ScanDirBlocSuccess) {
|
||||
yield newState;
|
||||
} else if (newState is ScanDirBlocFailure) {
|
||||
yield ScanDirBlocFailure(
|
||||
ev.account, cacheState.files, newState.exception);
|
||||
yield ScanDirBlocFailure(ev.account, state.files, newState.exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue