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<String> get activeAppID;
BehaviorSubject<AppImplementation> get activeApp;
BehaviorSubject get openNotifications;
@ -47,8 +47,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
initialApp = result.requireData.first.id;
}
}
if (!activeAppID.hasValue) {
await setActiveApp(initialApp!);
if (!activeApp.hasValue && initialApp != null) {
await setActiveApp(initialApp);
}
}),
);
@ -132,7 +132,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(apps.close());
unawaited(appImplementations.close());
unawaited(notificationsAppImplementation.close());
unawaited(activeAppID.close());
unawaited(activeApp.close());
unawaited(openNotifications.close());
unawaited(appVersions.close());
@ -144,7 +144,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
}
@override
BehaviorSubject<String> activeAppID = BehaviorSubject<String>();
BehaviorSubject<AppImplementation> activeApp = BehaviorSubject<AppImplementation>();
@override
BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
@ -176,14 +176,17 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
@override
Future setActiveApp(final String appID) async {
if (appID == 'notifications') {
openNotifications.add(null);
return;
}
final apps = await appImplementations.firstWhere((final a) => a.hasData);
if (apps.requireData.tryFind(appID) != null) {
// TODO: make activeAppID distinct
if (activeAppID.valueOrNull != appID) {
activeAppID.add(appID);
final app = apps.requireData.tryFind(appID);
if (app != null) {
if (activeApp.valueOrNull?.id != appID) {
activeApp.add(app);
}
} else if (appID == 'notifications') {
openNotifications.add(null);
} else {
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
Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String>(
stream: _appsBloc.activeAppID,
builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>(
builder: (final context, final appImplementations) => StreamBuilder<AppImplementation>(
stream: _appsBloc.activeApp,
builder: (final context, final activeAppSnapshot) => OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode,
builder: (final context, final navigationMode) {
final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible;
@ -124,9 +124,9 @@ class _HomePageState extends State<HomePage> {
),
),
] else ...[
if (activeAppIDSnapshot.hasData) ...[
if (activeAppSnapshot.hasData) ...[
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(
stream: appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String?>(
stream: appsBloc.activeAppID,
builder: (final context, final activeAppIDSnapshot) => AppBar(
builder: (final context, final appImplementations) => StreamBuilder<AppImplementation>(
stream: appsBloc.activeApp,
builder: (final context, final activeAppSnapshot) => AppBar(
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
if (appImplementations.hasData && activeAppIDSnapshot.hasData) ...[
if (activeAppSnapshot.hasData) ...[
Flexible(
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;
_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(
vsync: this,

Loading…
Cancel
Save