Browse Source

neon: add make AppsBlocStates supply the active AppImplementation

pull/411/head
Nikolas Rimikis 1 year ago
parent
commit
de01354e78
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 25
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 10
      packages/neon/neon/lib/src/pages/home.dart
  3. 10
      packages/neon/neon/lib/src/widgets/app_bar.dart
  4. 2
      packages/neon/neon/lib/src/widgets/drawer.dart

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

@ -13,7 +13,7 @@ abstract class AppsBlocStates {
BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation; BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation;
BehaviorSubject<String> get activeAppID; BehaviorSubject<AppImplementation> get activeApp;
BehaviorSubject get openNotifications; BehaviorSubject get openNotifications;
@ -47,8 +47,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
initialApp = result.requireData.first.id; initialApp = result.requireData.first.id;
} }
} }
if (!activeAppID.hasValue) { if (!activeApp.hasValue && initialApp != null) {
await setActiveApp(initialApp!); await setActiveApp(initialApp);
} }
}), }),
); );
@ -132,7 +132,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(apps.close()); unawaited(apps.close());
unawaited(appImplementations.close()); unawaited(appImplementations.close());
unawaited(notificationsAppImplementation.close()); unawaited(notificationsAppImplementation.close());
unawaited(activeAppID.close()); unawaited(activeApp.close());
unawaited(openNotifications.close()); unawaited(openNotifications.close());
unawaited(appVersions.close()); unawaited(appVersions.close());
@ -144,7 +144,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
@override @override
BehaviorSubject<String> activeAppID = BehaviorSubject<String>(); BehaviorSubject<AppImplementation> activeApp = BehaviorSubject<AppImplementation>();
@override @override
BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations = BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
@ -176,14 +176,17 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override @override
Future setActiveApp(final String appID) async { Future setActiveApp(final String appID) async {
if (appID == 'notifications') {
openNotifications.add(null);
return;
}
final apps = await appImplementations.firstWhere((final a) => a.hasData); final apps = await appImplementations.firstWhere((final a) => a.hasData);
if (apps.requireData.tryFind(appID) != null) { final app = apps.requireData.tryFind(appID);
// TODO: make activeAppID distinct if (app != null) {
if (activeAppID.valueOrNull != appID) { if (activeApp.valueOrNull?.id != appID) {
activeAppID.add(appID); activeApp.add(app);
} }
} else if (appID == 'notifications') {
openNotifications.add(null);
} else { } else {
throw Exception('App $appID not found'); throw Exception('App $appID not found');
} }

10
packages/neon/neon/lib/src/pages/home.dart

@ -100,9 +100,9 @@ class _HomePageState extends State<HomePage> {
@override @override
Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject( Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations, stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String>( builder: (final context, final appImplementations) => StreamBuilder<AppImplementation>(
stream: _appsBloc.activeAppID, stream: _appsBloc.activeApp,
builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>( builder: (final context, final activeAppSnapshot) => OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode, option: _globalOptions.navigationMode,
builder: (final context, final navigationMode) { builder: (final context, final navigationMode) {
final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible; final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible;
@ -124,9 +124,9 @@ class _HomePageState extends State<HomePage> {
), ),
), ),
] else ...[ ] else ...[
if (activeAppIDSnapshot.hasData) ...[ if (activeAppSnapshot.hasData) ...[
Expanded( Expanded(
child: appImplementations.requireData.find(activeAppIDSnapshot.requireData).page, child: activeAppSnapshot.requireData.page,
), ),
], ],
], ],

10
packages/neon/neon/lib/src/widgets/app_bar.dart

@ -23,18 +23,18 @@ class NeonAppBar extends StatelessWidget implements PreferredSizeWidget {
return ResultBuilder<Iterable<AppImplementation>>.behaviorSubject( return ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: appsBloc.appImplementations, stream: appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String?>( builder: (final context, final appImplementations) => StreamBuilder<AppImplementation>(
stream: appsBloc.activeAppID, stream: appsBloc.activeApp,
builder: (final context, final activeAppIDSnapshot) => AppBar( builder: (final context, final activeAppSnapshot) => AppBar(
title: Column( title: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
if (appImplementations.hasData && activeAppIDSnapshot.hasData) ...[ if (activeAppSnapshot.hasData) ...[
Flexible( Flexible(
child: Text( child: Text(
appImplementations.requireData.find(activeAppIDSnapshot.data!).name(context), activeAppSnapshot.requireData.name(context),
), ),
), ),
], ],

2
packages/neon/neon/lib/src/widgets/drawer.dart

@ -61,7 +61,7 @@ class __NeonDrawerState extends State<_NeonDrawer> with SingleTickerProviderStat
_appsBloc = _accountsBloc.activeAppsBloc; _appsBloc = _accountsBloc.activeAppsBloc;
_apps = widget.apps.toList(); _apps = widget.apps.toList();
_activeApp = _apps.indexWhere((final app) => app.id == _appsBloc.activeAppID.valueOrNull); _activeApp = _apps.indexWhere((final app) => app.id == _appsBloc.activeApp.valueOrNull?.id);
_tabController = TabController( _tabController = TabController(
vsync: this, vsync: this,

Loading…
Cancel
Save