From 86cae031339f308dd5b943ca6f9eee6f7e2ac4a6 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 28 Jun 2022 12:26:49 -0300 Subject: [PATCH 01/13] add none option --- app/containers/ActionSheet/Item.tsx | 9 ++++++++- app/containers/ActionSheet/Provider.tsx | 2 +- app/containers/ActionSheet/styles.ts | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/containers/ActionSheet/Item.tsx b/app/containers/ActionSheet/Item.tsx index 2b0b500804e..98d94314b8c 100644 --- a/app/containers/ActionSheet/Item.tsx +++ b/app/containers/ActionSheet/Item.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-nested-ternary */ import React from 'react'; import { Text, View } from 'react-native'; @@ -26,7 +27,13 @@ export const Item = React.memo(({ item, hide }: IActionSheetItem) => { style={[styles.item, { backgroundColor: themes[theme].focusedBackground }]} theme={theme} testID={item.testID}> - + {item.icon ? ( + item.icon === 'none' ? ( + + ) : ( + + ) + ) : null} void; diff --git a/app/containers/ActionSheet/styles.ts b/app/containers/ActionSheet/styles.ts index 68d371ea6f5..e78f3895c3f 100644 --- a/app/containers/ActionSheet/styles.ts +++ b/app/containers/ActionSheet/styles.ts @@ -63,5 +63,6 @@ export default StyleSheet.create({ }, rightContainer: { paddingLeft: 12 - } + }, + none: { width: 20 } }); From 48463d0eb0637fd5f8366a8b9c723d4c12f571b0 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 28 Jun 2022 12:28:18 -0300 Subject: [PATCH 02/13] create showErrorAlertWithEMessage function --- app/lib/methods/helpers/info.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/lib/methods/helpers/info.ts b/app/lib/methods/helpers/info.ts index d3b85c334e1..fd81618ceec 100644 --- a/app/lib/methods/helpers/info.ts +++ b/app/lib/methods/helpers/info.ts @@ -5,6 +5,14 @@ import I18n from '../../../i18n'; export const showErrorAlert = (message: string, title?: string, onPress = () => {}): void => Alert.alert(title!, message, [{ text: 'OK', onPress }], { cancelable: true }); +export const showErrorAlertWithEMessage = (e: any): void => { + const messageError = + e.data && e.data.error.includes('[error-too-many-requests]') + ? I18n.t('error-too-many-requests', { seconds: e.data.error.replace(/\D/g, '') }) + : e.data.errorType; + showErrorAlert(messageError); +}; + interface IShowConfirmationAlert { title?: string; message: string; From 12819773aa807c700bfb0700020b7ed8469f48a0 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 28 Jun 2022 12:29:42 -0300 Subject: [PATCH 03/13] migrate NotificationPreferencesView to hooks and improves overall --- .../NotificationPreferencesView/index.tsx | 459 ++++++++---------- 1 file changed, 205 insertions(+), 254 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index aa2931f0fe1..1ceb5db5197 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -1,282 +1,233 @@ -import React from 'react'; -import { StyleSheet, Switch, Text } from 'react-native'; -import { RouteProp } from '@react-navigation/core'; -import { StackNavigationProp } from '@react-navigation/stack'; -import { Observable, Subscription } from 'rxjs'; -import { connect } from 'react-redux'; +import { RouteProp, useNavigation, useRoute } from '@react-navigation/core'; +import React, { useEffect, useState } from 'react'; +import { Switch, Text } from 'react-native'; -import database from '../../lib/database'; -import { SWITCH_TRACK_COLOR, themes } from '../../lib/constants'; -import StatusBar from '../../containers/StatusBar'; +import { TActionSheetOptionsItem, useActionSheet } from '../../containers/ActionSheet'; import * as List from '../../containers/List'; -import I18n from '../../i18n'; -import { TSupportedThemes, withTheme } from '../../theme'; -import protectedFunction from '../../lib/methods/helpers/protectedFunction'; import SafeAreaView from '../../containers/SafeAreaView'; +import StatusBar from '../../containers/StatusBar'; +import { IRoomNotifications, TRoomNotificationsModel } from '../../definitions'; +import I18n from '../../i18n'; +import { SWITCH_TRACK_COLOR } from '../../lib/constants'; +import { useAppSelector } from '../../lib/hooks'; +import { showErrorAlertWithEMessage } from '../../lib/methods/helpers'; +import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion'; import log, { events, logEvent } from '../../lib/methods/helpers/log'; +import { Services } from '../../lib/services'; +import { ChatsStackParamList } from '../../stacks/types'; +import { useTheme } from '../../theme'; import sharedStyles from '../Styles'; import { IOptionsField, OPTIONS } from './options'; -import { ChatsStackParamList } from '../../stacks/types'; -import { IApplicationState, IRoomNotifications, TRoomNotificationsModel } from '../../definitions'; -import { Services } from '../../lib/services'; -import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion'; - -const styles = StyleSheet.create({ - pickerText: { - ...sharedStyles.textRegular, - fontSize: 16 - } -}); -interface INotificationPreferencesViewProps { - navigation: StackNavigationProp; - route: RouteProp; - theme: TSupportedThemes; - serverVersion: string | null; -} - -interface INotificationPreferencesViewState { +interface IBaseParams { + preference: string; room: TRoomNotificationsModel; + onChangeValue: (pref: string, param: { [key: string]: string }, onError: () => void) => void; } -class NotificationPreferencesView extends React.Component { - static navigationOptions = () => ({ - title: I18n.t('Notification_Preferences') - }); - - private mounted: boolean; - private rid: string; - private roomObservable?: Observable; - private subscription?: Subscription; - - constructor(props: INotificationPreferencesViewProps) { - super(props); - this.mounted = false; - this.rid = props.route.params?.rid ?? ''; - const room = props.route.params?.room; - this.state = { - room: room || {} - }; - if (room && room.observe) { - this.roomObservable = room.observe(); - this.subscription = this.roomObservable.subscribe(changes => { - if (this.mounted) { - this.setState({ room: changes }); - } else { - // @ts-ignore - this.state.room = changes; - } - }); - } - } - - componentDidMount() { - this.mounted = true; - } +const RenderListPicker = React.memo( + ({ + preference, + room, + title, + testID, + onChangeValue + }: { + title: string; + testID: string; + } & IBaseParams) => { + const { showActionSheet, hideActionSheet } = useActionSheet(); + const { colors } = useTheme(); + + const pref = room[preference] + ? OPTIONS[preference].find(option => option.value === room[preference]) + : (OPTIONS[preference][0] as IOptionsField); + + const [option, setOption] = useState(pref); + + const options: TActionSheetOptionsItem[] = OPTIONS[preference].map(i => ({ + title: I18n.t(i.label, { defaultValue: i.label, second: i.second }), + onPress: () => { + hideActionSheet(); + onChangeValue(preference, { [preference]: i.value.toString() }, () => setOption(option)); + setOption(i); + }, + icon: option?.value === i.value ? 'check' : 'none' + })); - componentWillUnmount() { - if (this.subscription && this.subscription.unsubscribe) { - this.subscription.unsubscribe(); - } + return ( + showActionSheet({ options })} + right={() => ( + + {option?.label ? I18n.t(option?.label, { defaultValue: option?.label, second: option?.second }) : option?.label} + + )} + /> + ); } +); + +const RenderSwitch = ({ preference, room, onChangeValue }: IBaseParams) => { + const [switchValue, setSwitchValue] = useState(!room[preference]); + return ( + { + onChangeValue(preference, { [preference]: switchValue ? '1' : '0' }, () => setSwitchValue(switchValue)); + setSwitchValue(value); + }} + /> + ); +}; + +const NotificationPreferencesView = () => { + const navigation = useNavigation(); + const route = useRoute>(); + const serverVersion = useAppSelector(state => state.server.version); + + useEffect(() => { + navigation.setOptions({ + title: I18n.t('Notification_Preferences') + }); + }, []); - saveNotificationSettings = async (key: string, value: string | boolean, params: IRoomNotifications) => { - // @ts-ignore - logEvent(events[`NP_${key.toUpperCase()}`]); - const { room } = this.state; - const db = database.active; + const rid = route.params?.rid ?? ''; + const room = route.params?.room; + const saveNotificationSettings = async (key: string, params: IRoomNotifications, onError: Function) => { try { - await db.write(async () => { - await room.update( - protectedFunction((r: IRoomNotifications) => { - r[key] = value; - }) - ); - }); - - try { - const result = await Services.saveNotificationSettings(this.rid, params); - if (result.success) { - return; - } - } catch { - // do nothing - } - - await db.write(async () => { - await room.update( - protectedFunction((r: IRoomNotifications) => { - r[key] = room[key]; - }) - ); - }); + // @ts-ignore + logEvent(events[`NP_${key.toUpperCase()}`]); + await Services.saveNotificationSettings(rid, params); } catch (e) { // @ts-ignore logEvent(events[`NP_${key.toUpperCase()}_F`]); log(e); + onError(); + showErrorAlertWithEMessage(e); } }; - onValueChangeSwitch = (key: string, value: string | boolean) => - this.saveNotificationSettings(key, value, { [key]: value ? '1' : '0' }); - - onValueChangePicker = (key: string, value: string) => this.saveNotificationSettings(key, value, { [key]: value.toString() }); - - pickerSelection = (title: string, key: string) => { - const { room } = this.state; - const { navigation } = this.props; - navigation.navigate('PickerView', { - title, - data: OPTIONS[key], - value: room[key], - onChangeValue: (value: string) => this.onValueChangePicker(key, value) - }); - }; - - renderPickerOption = (key: string) => { - const { room } = this.state; - const { theme } = this.props; - const text = room[key] ? OPTIONS[key].find(option => option.value === room[key]) : (OPTIONS[key][0] as IOptionsField); - return ( - - {text?.label ? I18n.t(text?.label, { defaultValue: text?.label, second: text?.second }) : text?.label} - - ); - }; - - renderSwitch = (key: string) => { - const { room } = this.state; - return ( - this.onValueChangeSwitch(key, !value)} - /> - ); - }; - - render() { - const { serverVersion } = this.props; - const { room } = this.state; - return ( - - - + return ( + + + + + + } + /> + + + + + + + } + /> + + + + + + + } + /> + + + + + {room.hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? ( this.renderSwitch('disableNotifications')} + title='Show_badge_for_mentions' + testID='notification-preference-view-badge-for-mentions' + right={() => } /> - + - - - - this.renderSwitch('muteGroupMentions')} - /> - - - - - - - this.renderSwitch('hideUnreadStatus')} - /> - - - - - {room.hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? ( - - - this.renderSwitch('hideMentionStatus')} - /> - - - - ) : null} - - - - this.pickerSelection(title, 'desktopNotifications')} - right={() => this.renderPickerOption('desktopNotifications')} - /> - - - - - - - this.pickerSelection(title, 'mobilePushNotifications')} - right={() => this.renderPickerOption('mobilePushNotifications')} - /> - - - - - - - this.pickerSelection(title, 'audioNotifications')} - right={() => this.renderPickerOption('audioNotifications')} - /> - - this.pickerSelection(title, 'audioNotificationValue')} - right={() => this.renderPickerOption('audioNotificationValue')} - /> - - this.pickerSelection(title, 'desktopNotificationDuration')} - right={() => this.renderPickerOption('desktopNotificationDuration')} - /> - - - - - - this.pickerSelection(title, 'emailNotifications')} - right={() => this.renderPickerOption('emailNotifications')} - /> - - - - - ); - } -} - -const mapStateToProps = (state: IApplicationState) => ({ - serverVersion: state.server.version -}); - -export default connect(mapStateToProps)(withTheme(NotificationPreferencesView)); + ) : null} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default NotificationPreferencesView; From e517c89dca6acb86cbe259fc1a1388eb7e16c26e Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 28 Jun 2022 16:41:35 -0300 Subject: [PATCH 04/13] change icon to right --- app/containers/ActionSheet/Item.tsx | 11 +++++------ app/containers/ActionSheet/Provider.tsx | 2 +- app/containers/ActionSheet/styles.ts | 1 - app/views/NotificationPreferencesView/index.tsx | 3 ++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/containers/ActionSheet/Item.tsx b/app/containers/ActionSheet/Item.tsx index 98d94314b8c..f04949e4402 100644 --- a/app/containers/ActionSheet/Item.tsx +++ b/app/containers/ActionSheet/Item.tsx @@ -28,16 +28,15 @@ export const Item = React.memo(({ item, hide }: IActionSheetItem) => { theme={theme} testID={item.testID}> {item.icon ? ( - item.icon === 'none' ? ( - - ) : ( - - ) + ) : null} + style={[ + styles.title, + { color: item.danger ? themes[theme].dangerColor : themes[theme].bodyText, marginLeft: item.icon ? 16 : 0 } + ]}> {item.title} diff --git a/app/containers/ActionSheet/Provider.tsx b/app/containers/ActionSheet/Provider.tsx index 2219217c0e3..4919eba0b1d 100644 --- a/app/containers/ActionSheet/Provider.tsx +++ b/app/containers/ActionSheet/Provider.tsx @@ -5,7 +5,7 @@ import { TIconsName } from '../CustomIcon'; export type TActionSheetOptionsItem = { title: string; - icon: TIconsName | 'none'; + icon?: TIconsName; danger?: boolean; testID?: string; onPress: () => void; diff --git a/app/containers/ActionSheet/styles.ts b/app/containers/ActionSheet/styles.ts index e78f3895c3f..29173dfcd11 100644 --- a/app/containers/ActionSheet/styles.ts +++ b/app/containers/ActionSheet/styles.ts @@ -27,7 +27,6 @@ export default StyleSheet.create({ }, title: { fontSize: 16, - marginLeft: 16, ...sharedStyles.textRegular }, handle: { diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index 1ceb5db5197..0da4fee6daf 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import { Switch, Text } from 'react-native'; import { TActionSheetOptionsItem, useActionSheet } from '../../containers/ActionSheet'; +import { CustomIcon } from '../../containers/CustomIcon'; import * as List from '../../containers/List'; import SafeAreaView from '../../containers/SafeAreaView'; import StatusBar from '../../containers/StatusBar'; @@ -52,7 +53,7 @@ const RenderListPicker = React.memo( onChangeValue(preference, { [preference]: i.value.toString() }, () => setOption(option)); setOption(i); }, - icon: option?.value === i.value ? 'check' : 'none' + right: option?.value === i.value ? () => : undefined })); return ( From e8ae963d087c87df2d8e61198ec029b1229bd43b Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 28 Jun 2022 16:42:45 -0300 Subject: [PATCH 05/13] fix navigation options --- app/stacks/InsideStack.tsx | 6 +----- app/stacks/MasterDetailStack/index.tsx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/stacks/InsideStack.tsx b/app/stacks/InsideStack.tsx index 6a525d57537..008356a8069 100644 --- a/app/stacks/InsideStack.tsx +++ b/app/stacks/InsideStack.tsx @@ -110,11 +110,7 @@ const ChatsStackNavigator = () => { - + diff --git a/app/stacks/MasterDetailStack/index.tsx b/app/stacks/MasterDetailStack/index.tsx index 4e6b4a0105a..0726c61ad3f 100644 --- a/app/stacks/MasterDetailStack/index.tsx +++ b/app/stacks/MasterDetailStack/index.tsx @@ -150,11 +150,7 @@ const ModalStackNavigator = React.memo(({ navigation }: INavigation) => { options={props => DirectoryView.navigationOptions!({ ...props, isMasterDetail: true })} /> - + From 3ae2f79a2b0f5bb5d9f14c7051d4eca1bf835a5a Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 19 Jul 2022 11:19:51 -0300 Subject: [PATCH 06/13] remove none --- app/containers/ActionSheet/styles.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/containers/ActionSheet/styles.ts b/app/containers/ActionSheet/styles.ts index 29173dfcd11..2bc6114b62e 100644 --- a/app/containers/ActionSheet/styles.ts +++ b/app/containers/ActionSheet/styles.ts @@ -62,6 +62,5 @@ export default StyleSheet.create({ }, rightContainer: { paddingLeft: 12 - }, - none: { width: 20 } + } }); From 533cd88dbd5f97fb0b4ccc21fdca8fa2eb66ae6d Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 19 Jul 2022 11:20:44 -0300 Subject: [PATCH 07/13] fix types --- app/definitions/IRoom.ts | 1 + .../NotificationPreferencesView/index.tsx | 20 +++++++++++-------- .../NotificationPreferencesView/options.ts | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index 1444d4fef2d..d49eccf676b 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -237,6 +237,7 @@ export interface IRoomNotifications { desktopNotifications?: TNotifications; mobilePushNotifications?: TNotifications; emailNotifications?: TNotifications; + hideMentionStatus?: boolean; } export type TRoomNotificationsModel = IRoomNotifications & Model; diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index 0da4fee6daf..07f887fb39a 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -18,12 +18,16 @@ import { Services } from '../../lib/services'; import { ChatsStackParamList } from '../../stacks/types'; import { useTheme } from '../../theme'; import sharedStyles from '../Styles'; -import { IOptionsField, OPTIONS } from './options'; +import { OPTIONS } from './options'; + +type TOptions = keyof typeof OPTIONS; +type TRoomNotifications = keyof IRoomNotifications; +type TUnionOptionsRoomNotifications = TOptions | TRoomNotifications; interface IBaseParams { - preference: string; + preference: TUnionOptionsRoomNotifications; room: TRoomNotificationsModel; - onChangeValue: (pref: string, param: { [key: string]: string }, onError: () => void) => void; + onChangeValue: (pref: TUnionOptionsRoomNotifications, param: { [key: string]: string }, onError: () => void) => void; } const RenderListPicker = React.memo( @@ -41,12 +45,12 @@ const RenderListPicker = React.memo( const { colors } = useTheme(); const pref = room[preference] - ? OPTIONS[preference].find(option => option.value === room[preference]) - : (OPTIONS[preference][0] as IOptionsField); + ? OPTIONS[preference as TOptions].find(option => option.value === room[preference]) + : OPTIONS[preference as TOptions][0]; const [option, setOption] = useState(pref); - const options: TActionSheetOptionsItem[] = OPTIONS[preference].map(i => ({ + const options: TActionSheetOptionsItem[] = OPTIONS[preference as TOptions].map(i => ({ title: I18n.t(i.label, { defaultValue: i.label, second: i.second }), onPress: () => { hideActionSheet(); @@ -76,7 +80,7 @@ const RenderSwitch = ({ preference, room, onChangeValue }: IBaseParams) => { return ( { onChangeValue(preference, { [preference]: switchValue ? '1' : '0' }, () => setSwitchValue(switchValue)); @@ -100,7 +104,7 @@ const NotificationPreferencesView = () => { const rid = route.params?.rid ?? ''; const room = route.params?.room; - const saveNotificationSettings = async (key: string, params: IRoomNotifications, onError: Function) => { + const saveNotificationSettings = async (key: TUnionOptionsRoomNotifications, params: IRoomNotifications, onError: Function) => { try { // @ts-ignore logEvent(events[`NP_${key.toUpperCase()}`]); diff --git a/app/views/NotificationPreferencesView/options.ts b/app/views/NotificationPreferencesView/options.ts index a2b3251c6a2..a79b29dd8ba 100644 --- a/app/views/NotificationPreferencesView/options.ts +++ b/app/views/NotificationPreferencesView/options.ts @@ -4,7 +4,7 @@ export interface IOptionsField { second?: number; } export interface INotificationOptions { - [desktopNotifications: string]: IOptionsField[]; + desktopNotifications: IOptionsField[]; audioNotifications: IOptionsField[]; mobilePushNotifications: IOptionsField[]; emailNotifications: IOptionsField[]; From 1923586c79c87f4ac0c95c0b924b04696f8ea245 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 19 Jul 2022 11:22:48 -0300 Subject: [PATCH 08/13] remove memo --- .../NotificationPreferencesView/index.tsx | 86 +++++++++---------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index 07f887fb39a..f02a555a68f 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -30,50 +30,48 @@ interface IBaseParams { onChangeValue: (pref: TUnionOptionsRoomNotifications, param: { [key: string]: string }, onError: () => void) => void; } -const RenderListPicker = React.memo( - ({ - preference, - room, - title, - testID, - onChangeValue - }: { - title: string; - testID: string; - } & IBaseParams) => { - const { showActionSheet, hideActionSheet } = useActionSheet(); - const { colors } = useTheme(); - - const pref = room[preference] - ? OPTIONS[preference as TOptions].find(option => option.value === room[preference]) - : OPTIONS[preference as TOptions][0]; - - const [option, setOption] = useState(pref); - - const options: TActionSheetOptionsItem[] = OPTIONS[preference as TOptions].map(i => ({ - title: I18n.t(i.label, { defaultValue: i.label, second: i.second }), - onPress: () => { - hideActionSheet(); - onChangeValue(preference, { [preference]: i.value.toString() }, () => setOption(option)); - setOption(i); - }, - right: option?.value === i.value ? () => : undefined - })); - - return ( - showActionSheet({ options })} - right={() => ( - - {option?.label ? I18n.t(option?.label, { defaultValue: option?.label, second: option?.second }) : option?.label} - - )} - /> - ); - } -); +const RenderListPicker = ({ + preference, + room, + title, + testID, + onChangeValue +}: { + title: string; + testID: string; +} & IBaseParams) => { + const { showActionSheet, hideActionSheet } = useActionSheet(); + const { colors } = useTheme(); + + const pref = room[preference] + ? OPTIONS[preference as TOptions].find(option => option.value === room[preference]) + : OPTIONS[preference as TOptions][0]; + + const [option, setOption] = useState(pref); + + const options: TActionSheetOptionsItem[] = OPTIONS[preference as TOptions].map(i => ({ + title: I18n.t(i.label, { defaultValue: i.label, second: i.second }), + onPress: () => { + hideActionSheet(); + onChangeValue(preference, { [preference]: i.value.toString() }, () => setOption(option)); + setOption(i); + }, + right: option?.value === i.value ? () => : undefined + })); + + return ( + showActionSheet({ options })} + right={() => ( + + {option?.label ? I18n.t(option?.label, { defaultValue: option?.label, second: option?.second }) : option?.label} + + )} + /> + ); +}; const RenderSwitch = ({ preference, room, onChangeValue }: IBaseParams) => { const [switchValue, setSwitchValue] = useState(!room[preference]); From 4ff938415595f27a5af29cef741722a02dd48399 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 19 Jul 2022 11:23:57 -0300 Subject: [PATCH 09/13] cleaning --- app/containers/ActionSheet/Item.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/app/containers/ActionSheet/Item.tsx b/app/containers/ActionSheet/Item.tsx index f04949e4402..7b48dcefd44 100644 --- a/app/containers/ActionSheet/Item.tsx +++ b/app/containers/ActionSheet/Item.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-nested-ternary */ import React from 'react'; import { Text, View } from 'react-native'; From bcf0480e6ba9c955f4510cbcc8db779c5e4cfe41 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Mon, 25 Jul 2022 13:41:27 -0300 Subject: [PATCH 10/13] switching to destructuring --- app/views/NotificationPreferencesView/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index f02a555a68f..80928bb3723 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -99,8 +99,7 @@ const NotificationPreferencesView = () => { }); }, []); - const rid = route.params?.rid ?? ''; - const room = route.params?.room; + const { rid, room } = route.params; const saveNotificationSettings = async (key: TUnionOptionsRoomNotifications, params: IRoomNotifications, onError: Function) => { try { From 92e8f5c76125e52048ffb87b005feb06e2ff92f6 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 27 Jul 2022 10:30:40 -0300 Subject: [PATCH 11/13] add observe for hideUnreadStatus --- app/views/NotificationPreferencesView/index.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index 80928bb3723..f4444596783 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -88,10 +88,12 @@ const RenderSwitch = ({ preference, room, onChangeValue }: IBaseParams) => { ); }; -const NotificationPreferencesView = () => { - const navigation = useNavigation(); +const NotificationPreferencesView = (): React.ReactElement => { const route = useRoute>(); + const { rid, room } = route.params; + const navigation = useNavigation(); const serverVersion = useAppSelector(state => state.server.version); + const [hideUnreadStatus, setHideUnreadStatus] = useState(room.hideUnreadStatus); useEffect(() => { navigation.setOptions({ @@ -99,7 +101,12 @@ const NotificationPreferencesView = () => { }); }, []); - const { rid, room } = route.params; + useEffect(() => { + const observe = room.observe(); + observe.subscribe(data => { + setHideUnreadStatus(data.hideUnreadStatus); + }); + }, []); const saveNotificationSettings = async (key: TUnionOptionsRoomNotifications, params: IRoomNotifications, onError: Function) => { try { @@ -152,7 +159,7 @@ const NotificationPreferencesView = () => { - {room.hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? ( + {hideUnreadStatus && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0') ? ( Date: Thu, 28 Jul 2022 10:06:31 -0300 Subject: [PATCH 12/13] fix desktop options --- .../NotificationPreferencesView/index.tsx | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/app/views/NotificationPreferencesView/index.tsx b/app/views/NotificationPreferencesView/index.tsx index f4444596783..7029e5a7dd0 100644 --- a/app/views/NotificationPreferencesView/index.tsx +++ b/app/views/NotificationPreferencesView/index.tsx @@ -181,6 +181,13 @@ const NotificationPreferencesView = (): React.ReactElement => { testID='notification-preference-view-alert' onChangeValue={saveNotificationSettings} /> + @@ -196,33 +203,6 @@ const NotificationPreferencesView = (): React.ReactElement => { - - - - - - - - - Date: Thu, 28 Jul 2022 10:08:49 -0300 Subject: [PATCH 13/13] remove unused options --- .../NotificationPreferencesView/options.ts | 51 ------------------- 1 file changed, 51 deletions(-) diff --git a/app/views/NotificationPreferencesView/options.ts b/app/views/NotificationPreferencesView/options.ts index a79b29dd8ba..ee98aebbb1c 100644 --- a/app/views/NotificationPreferencesView/options.ts +++ b/app/views/NotificationPreferencesView/options.ts @@ -5,10 +5,8 @@ export interface IOptionsField { } export interface INotificationOptions { desktopNotifications: IOptionsField[]; - audioNotifications: IOptionsField[]; mobilePushNotifications: IOptionsField[]; emailNotifications: IOptionsField[]; - desktopNotificationDuration: IOptionsField[]; audioNotificationValue: IOptionsField[]; } @@ -31,24 +29,6 @@ export const OPTIONS: INotificationOptions = { value: 'nothing' } ], - audioNotifications: [ - { - label: 'Default', - value: 'default' - }, - { - label: 'All_Messages', - value: 'all' - }, - { - label: 'Mentions', - value: 'mentions' - }, - { - label: 'Nothing', - value: 'nothing' - } - ], mobilePushNotifications: [ { label: 'Default', @@ -85,37 +65,6 @@ export const OPTIONS: INotificationOptions = { value: 'nothing' } ], - desktopNotificationDuration: [ - { - label: 'Default', - value: 0 - }, - { - label: 'Seconds', - second: 1, - value: 1 - }, - { - label: 'Seconds', - second: 2, - value: 2 - }, - { - label: 'Seconds', - second: 3, - value: 3 - }, - { - label: 'Seconds', - second: 4, - value: 4 - }, - { - label: 'Seconds', - second: 5, - value: 5 - } - ], audioNotificationValue: [ { label: 'None',