Browse Source

neon: Fix and cleanup apps bloc

pull/100/head
jld3103 2 years ago
parent
commit
07e3be7b92
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 18
      packages/neon/lib/src/blocs/apps.dart

18
packages/neon/lib/src/blocs/apps.dart

@ -64,13 +64,9 @@ class AppsBloc extends $AppsBloc {
result.data != null ? _filteredAppImplementations(result.data!) : <AppImplementation>[]; result.data != null ? _filteredAppImplementations(result.data!) : <AppImplementation>[];
if (result.data != null) { if (result.data != null) {
if (_accountsBloc.pushNotificationApp != null) {
setActiveApp(_accountsBloc.pushNotificationApp);
_accountsBloc.pushNotificationApp = null;
} else {
final options = _accountsBloc.getOptions(_account); final options = _accountsBloc.getOptions(_account);
unawaited( unawaited(
options.initialApp.stream.first.then((var initialApp) { options.initialApp.stream.first.then((var initialApp) async {
if (initialApp == null) { if (initialApp == null) {
if (appImplementations.where((final a) => a.id == 'files').isNotEmpty) { if (appImplementations.where((final a) => a.id == 'files').isNotEmpty) {
initialApp = 'files'; initialApp = 'files';
@ -86,7 +82,6 @@ class AppsBloc extends $AppsBloc {
}), }),
); );
} }
}
}); });
_loadApps(); _loadApps();
@ -120,17 +115,14 @@ class AppsBloc extends $AppsBloc {
final _appImplementationsSubject = BehaviorSubject<Result<List<AppImplementation>>>(); final _appImplementationsSubject = BehaviorSubject<Result<List<AppImplementation>>>();
late final _activeAppSubject = BehaviorSubject<String?>(); late final _activeAppSubject = BehaviorSubject<String?>();
final Map<AppImplementation, RxBlocBase> _blocs = {}; final Map<String, RxBlocBase> _blocs = {};
T getAppBloc<T extends RxBlocBase>(final AppImplementation appImplementation) { T getAppBloc<T extends RxBlocBase>(final AppImplementation appImplementation) {
if (_blocs[appImplementation] != null) { if (_blocs[appImplementation.id] != null) {
return _blocs[appImplementation]! as T; return _blocs[appImplementation.id]! as T;
} }
final bloc = appImplementation.buildBloc(_account.client); return _blocs[appImplementation.id] = appImplementation.buildBloc(_account.client) as T;
_blocs[appImplementation] = bloc;
return bloc as T;
} }
@override @override

Loading…
Cancel
Save