From fb695ad67e8d2a6fcc567ebd4aa02d64f12491ed Mon Sep 17 00:00:00 2001 From: migcarde Date: Thu, 9 May 2024 20:41:16 +0200 Subject: [PATCH 1/6] feat: integrate show notification button option --- .../lib/core/config/kv_keys.dart | 5 +++ .../notification_settings_cubit.dart | 34 +++++++++++++- .../widgets/notification_button.dart | 44 ++++++++++++------- .../widgets/settings_notifications_view.dart | 19 ++++++++ frontend/resources/translations/en.json | 4 ++ 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart index 748254d07d8e..b148e04bbdcb 100644 --- a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart +++ b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart @@ -65,6 +65,11 @@ class KVKeys { /// {'feature_flag_1': true, 'feature_flag_2': false} static const String featureFlag = 'featureFlag'; + /// The key for saving show notification icon option + /// + /// The value is a boolean string + static const String showNotificationIcon = 'showNotificationIcon'; + /// The key for saving the last opened workspace id /// /// The workspace id is a string. diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart index aae0a6360983..911d09850a19 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart @@ -1,5 +1,8 @@ import 'dart:async'; +import 'package:appflowy/core/config/kv.dart'; +import 'package:appflowy/core/config/kv_keys.dart'; +import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/user/application/user_settings_service.dart'; import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart'; @@ -19,6 +22,16 @@ class NotificationSettingsCubit extends Cubit { isNotificationsEnabled: _notificationSettings.notificationsEnabled, ), ); + getIt() + .getWithFormat( + KVKeys.showNotificationIcon, + (value) => bool.parse(value), + ) + .then( + (value) => state.copyWith( + isShowNotificationsIconEnabled: value ?? true, + ), + ); _initCompleter.complete(); }); } @@ -41,9 +54,24 @@ class NotificationSettingsCubit extends Cubit { await _saveNotificationSettings(); } + Future toogleShowNotificationIconEnabled() async { + await _initCompleter.future; + + emit( + state.copyWith( + isShowNotificationsIconEnabled: !state.isShowNotificationsIconEnabled, + ), + ); + } + Future _saveNotificationSettings() async { await _initCompleter.future; + await getIt().set( + KVKeys.showNotificationIcon, + state.isShowNotificationsIconEnabled.toString(), + ); + final result = await UserSettingsBackendService() .setNotificationSettings(_notificationSettings); result.fold( @@ -59,8 +87,12 @@ class NotificationSettingsState with _$NotificationSettingsState { const factory NotificationSettingsState({ required bool isNotificationsEnabled, + required bool isShowNotificationsIconEnabled, }) = _NotificationSettingsState; factory NotificationSettingsState.initial() => - const NotificationSettingsState(isNotificationsEnabled: true); + const NotificationSettingsState( + isNotificationsEnabled: true, + isShowNotificationsIconEnabled: true, + ); } diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart b/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart index a7925dc3f798..4f93f817df50 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart @@ -3,6 +3,7 @@ import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/user/application/reminder/reminder_bloc.dart'; import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart'; +import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart'; import 'package:appflowy/workspace/presentation/notifications/notification_dialog.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -24,23 +25,32 @@ class NotificationButton extends StatelessWidget { return BlocProvider.value( value: getIt(), - child: BlocBuilder( - builder: (context, state) => FlowyTooltip( - message: LocaleKeys.notificationHub_title.tr(), - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: AppFlowyPopover( - mutex: mutex, - direction: PopoverDirection.bottomWithLeftAligned, - constraints: const BoxConstraints(maxHeight: 500, maxWidth: 425), - windowPadding: EdgeInsets.zero, - margin: EdgeInsets.zero, - popupBuilder: (_) => - NotificationDialog(views: views, mutex: mutex), - child: _buildNotificationIcon(context, state.hasUnreads), - ), - ), - ), + child: BlocBuilder( + builder: (notificationSettingsContext, notificationSettingsState) { + return BlocBuilder( + builder: (context, state) => notificationSettingsState + .isShowNotificationsIconEnabled + ? FlowyTooltip( + message: LocaleKeys.notificationHub_title.tr(), + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: AppFlowyPopover( + mutex: mutex, + direction: PopoverDirection.bottomWithLeftAligned, + constraints: + const BoxConstraints(maxHeight: 500, maxWidth: 425), + windowPadding: EdgeInsets.zero, + margin: EdgeInsets.zero, + popupBuilder: (_) => + NotificationDialog(views: views, mutex: mutex), + child: + _buildNotificationIcon(context, state.hasUnreads), + ), + ), + ) + : const SizedBox(), + ); + }, ), ); } diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart index a930b55edf8f..6fdfab794a7a 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart @@ -34,6 +34,25 @@ class SettingsNotificationsView extends StatelessWidget { ), ], ), + FlowySettingListTile( + label: LocaleKeys + .settings_notifications_showNotificationsIcon_label + .tr(), + hint: LocaleKeys.settings_notifications_showNotificationsIcon_hint + .tr(), + trailing: [ + Switch( + value: state.isShowNotificationsIconEnabled, + splashRadius: 0, + activeColor: Theme.of(context).colorScheme.primary, + onChanged: (value) { + context + .read() + .toogleShowNotificationIconEnabled(); + }, + ), + ], + ), ], ); }, diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json index b1b35ee0d41e..7e1c5b7d380e 100644 --- a/frontend/resources/translations/en.json +++ b/frontend/resources/translations/en.json @@ -405,6 +405,10 @@ "enableNotifications": { "label": "Enable notifications", "hint": "Turn off to stop local notifications from appearing." + }, + "showNotificationsIcon": { + "label": "Show notifications icon", + "hint": "Turn off to hide notification icons in the app." } }, "appearance": { From 1c23188cabeb83a3cc928cacdfe5c07510c3cef5 Mon Sep 17 00:00:00 2001 From: migcarde Date: Fri, 10 May 2024 19:45:00 +0200 Subject: [PATCH 2/6] Update frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> --- .../settings/widgets/settings_notifications_view.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart index 6fdfab794a7a..a81061e222b5 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart @@ -45,11 +45,9 @@ class SettingsNotificationsView extends StatelessWidget { value: state.isShowNotificationsIconEnabled, splashRadius: 0, activeColor: Theme.of(context).colorScheme.primary, - onChanged: (value) { - context - .read() - .toogleShowNotificationIconEnabled(); - }, + onChanged: (_) => + context.read() + .toogleShowNotificationIconEnabled(), ), ], ), From cc1d216d05047af4ea08776ff8f064d29f3438b5 Mon Sep 17 00:00:00 2001 From: migcarde Date: Fri, 10 May 2024 19:45:08 +0200 Subject: [PATCH 3/6] Update frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> --- .../presentation/notifications/widgets/notification_button.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart b/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart index 4f93f817df50..1a2889093e20 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/notifications/widgets/notification_button.dart @@ -48,7 +48,7 @@ class NotificationButton extends StatelessWidget { ), ), ) - : const SizedBox(), + : const SizedBox.shrink(), ); }, ), From b4acc1951f0434ddfac03c4c11383c486fbbd126 Mon Sep 17 00:00:00 2001 From: migcarde Date: Fri, 10 May 2024 20:53:13 +0200 Subject: [PATCH 4/6] feat: applied proposal code --- .../notification_settings_cubit.dart | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart index 911d09850a19..dff815a06264 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart @@ -13,33 +13,31 @@ part 'notification_settings_cubit.freezed.dart'; class NotificationSettingsCubit extends Cubit { NotificationSettingsCubit() : super(NotificationSettingsState.initial()) { - UserSettingsBackendService() - .getNotificationSettings() - .then((notificationSettings) { - _notificationSettings = notificationSettings; - emit( - state.copyWith( - isNotificationsEnabled: _notificationSettings.notificationsEnabled, - ), - ); - getIt() - .getWithFormat( - KVKeys.showNotificationIcon, - (value) => bool.parse(value), - ) - .then( - (value) => state.copyWith( - isShowNotificationsIconEnabled: value ?? true, - ), - ); - _initCompleter.complete(); - }); + _initialize(); } final Completer _initCompleter = Completer(); late final NotificationSettingsPB _notificationSettings; + Future _initialize() async { + final settings = + await UserSettingsBackendService().getNotificationSettings(); + _notificationSettings = settings; + + final showNotificationSetting = await getIt() + .getWithFormat(KVKeys.showNotificationIcon, (v) => bool.parse(v)); + + emit( + state.copyWith( + isNotificationsEnabled: _notificationSettings.notificationsEnabled, + isShowNotificationsIconEnabled: showNotificationSetting ?? true, + ), + ); + + _initCompleter.complete(); + } + Future toggleNotificationsEnabled() async { await _initCompleter.future; From 4b0a21926f3c68d542daece42fa539879e7347d2 Mon Sep 17 00:00:00 2001 From: migcarde Date: Fri, 10 May 2024 23:18:21 +0200 Subject: [PATCH 5/6] Update frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> --- .../settings/notifications/notification_settings_cubit.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart index dff815a06264..ea6b3b6f0153 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/settings/notifications/notification_settings_cubit.dart @@ -21,9 +21,8 @@ class NotificationSettingsCubit extends Cubit { late final NotificationSettingsPB _notificationSettings; Future _initialize() async { - final settings = + _notificationSettings = await UserSettingsBackendService().getNotificationSettings(); - _notificationSettings = settings; final showNotificationSetting = await getIt() .getWithFormat(KVKeys.showNotificationIcon, (v) => bool.parse(v)); From 8d248f322f2bc904a00a26a56d7f2bd32281d185 Mon Sep 17 00:00:00 2001 From: migcarde Date: Wed, 15 May 2024 09:58:56 +0200 Subject: [PATCH 6/6] Merge branch 'main' into feature/option-to-not-show-notifications-icon --- .../settings/widgets/settings_notifications_view.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart index b89dc34a60aa..f7dcb635074c 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_notifications_view.dart @@ -33,7 +33,7 @@ class SettingsNotificationsView extends StatelessWidget { ), ], ), - FlowySettingListTile( + SettingListTile( label: LocaleKeys .settings_notifications_showNotificationsIcon_label .tr(), @@ -44,9 +44,9 @@ class SettingsNotificationsView extends StatelessWidget { value: state.isShowNotificationsIconEnabled, splashRadius: 0, activeColor: Theme.of(context).colorScheme.primary, - onChanged: (_) => - context.read() - .toogleShowNotificationIconEnabled(), + onChanged: (_) => context + .read() + .toogleShowNotificationIconEnabled(), ), ], ),