Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: integrate show notification button option (#5302)

migcarde526de2eb5c6c
diff --git a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart
index fb224abe25..00e79153e4 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 aae0a63609..ea6b3b6f01 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';
@@ -10,23 +13,30 @@ part 'notification_settings_cubit.freezed.dart';
class NotificationSettingsCubit extends Cubit<NotificationSettingsState> {
NotificationSettingsCubit() : super(NotificationSettingsState.initial()) {
- UserSettingsBackendService()
- .getNotificationSettings()
- .then((notificationSettings) {
- _notificationSettings = notificationSettings;
- emit(
- state.copyWith(
- isNotificationsEnabled: _notificationSettings.notificationsEnabled,
- ),
- );
- _initCompleter.complete();
- });
+ _initialize();
}
final Completer<void> _initCompleter = Completer();
late final NotificationSettingsPB _notificationSettings;
+ Future<void> _initialize() async {
+ _notificationSettings =
+ await UserSettingsBackendService().getNotificationSettings();
+
+ final showNotificationSetting = await getIt<KeyValueStorage>()
+ .getWithFormat(KVKeys.showNotificationIcon, (v) => bool.parse(v));
+
+ emit(
+ state.copyWith(
+ isNotificationsEnabled: _notificationSettings.notificationsEnabled,
+ isShowNotificationsIconEnabled: showNotificationSetting ?? true,
+ ),
+ );
+
+ _initCompleter.complete();
+ }
+
Future<void> toggleNotificationsEnabled() async {
await _initCompleter.future;
@@ -41,9 +51,24 @@ class NotificationSettingsCubit extends Cubit<NotificationSettingsState> {
await _saveNotificationSettings();
}
+ Future<void> toogleShowNotificationIconEnabled() async {
+ await _initCompleter.future;
+
+ emit(
+ state.copyWith(
+ isShowNotificationsIconEnabled: !state.isShowNotificationsIconEnabled,
+ ),
+ );
+ }
+
Future<void> _saveNotificationSettings() async {
await _initCompleter.future;
+ await getIt<KeyValueStorage>().set(
+ KVKeys.showNotificationIcon,
+ state.isShowNotificationsIconEnabled.toString(),
+ );
+
final result = await UserSettingsBackendService()
.setNotificationSettings(_notificationSettings);
result.fold(
@@ -59,8 +84,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 61fba3bd65..08f421951b 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/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/notifications/notification_dialog.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
@@ -25,25 +26,35 @@ class NotificationButton extends StatelessWidget {
return BlocProvider<ReminderBloc>.value(
value: getIt<ReminderBloc>(),
- child: BlocBuilder<ReminderBloc, ReminderState>(
- builder: (context, state) => FlowyTooltip(
- message: LocaleKeys.notificationHub_title.tr(),
- 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: SizedBox.square(
- dimension: HomeSizes.workspaceSectionHeight,
- child: FlowyButton(
- useIntrinsicWidth: true,
- text: _buildNotificationIcon(context, state.hasUnreads),
- ),
- ),
- ),
- ),
+ child: BlocBuilder<NotificationSettingsCubit, NotificationSettingsState>(
+ builder: (notificationSettingsContext, notificationSettingsState) {
+ return BlocBuilder<ReminderBloc, ReminderState>(
+ builder: (context, state) => notificationSettingsState
+ .isShowNotificationsIconEnabled
+ ? FlowyTooltip(
+ message: LocaleKeys.notificationHub_title.tr(),
+ 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: SizedBox.square(
+ dimension: HomeSizes.workspaceSectionHeight,
+ child: FlowyButton(
+ useIntrinsicWidth: true,
+ text:
+ _buildNotificationIcon(context, state.hasUnreads),
+ ),
+ ),
+ ),
+ )
+ : const SizedBox.shrink(),
+ );
+ },
),
);
}
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 1b3250ee55..f7dcb63507 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,6 +33,23 @@ class SettingsNotificationsView extends StatelessWidget {
),
],
),
+ SettingListTile(
+ 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: (_) => context
+ .read<NotificationSettingsCubit>()
+ .toogleShowNotificationIconEnabled(),
+ ),
+ ],
+ ),
],
);
},
diff --git a/frontend/resources/translations/de-DE.json b/frontend/resources/translations/de-DE.json
index 30b76b9966..f0c08ca52e 100644
--- a/frontend/resources/translations/de-DE.json
+++ b/frontend/resources/translations/de-DE.json
@@ -65,7 +65,7 @@
"alreadyHaveAnAccount": "Du hast bereits ein Konto?",
"logIn": "Anmeldung",
"generalError": "Etwas ist schiefgelaufen. Bitte versuche es später noch einmal",
- "limitRateError": "Aus Sicherheitsgründen kannst du nur alle 60 Sekunden einen Authentifizierungslink anfordern",
+ "limitRateError": "Aus Sicherheitsgründen kannst du nur alle 60 Sekunden einen Authentifizierungslink anfordern"
},
"workspace": {
"chooseWorkspace": "Arbeitsbereich wählen",
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index 5b7de6a4d6..03a21fdedb 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -547,6 +547,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": {
diff --git a/frontend/resources/translations/es-VE.json b/frontend/resources/translations/es-VE.json
index 893b6da9e7..6177cd5377 100644
--- a/frontend/resources/translations/es-VE.json
+++ b/frontend/resources/translations/es-VE.json
@@ -64,7 +64,7 @@
"alreadyHaveAnAccount": "¿Ya tienes cuenta?",
"logIn": "Iniciar sesión",
"generalError": "Algo ha salido mal. Por favor, inténtalo más tarde",
- "limitRateError": "Por razones de seguridad, solo puedes solicitar un enlace mágico cada 60 segundos",
+ "limitRateError": "Por razones de seguridad, solo puedes solicitar un enlace mágico cada 60 segundos"
},
"workspace": {
"chooseWorkspace": "Elige tu espacio de trabajo",