@@ -8,26 +8,22 @@ import invariant from 'invariant';
8
8
import type { RouteProp } from '../react-navigation' ;
9
9
import type { AppNavigationProp } from '../nav/AppNavigator' ;
10
10
import { useGlobalSelector , useSelector } from '../react-redux' ;
11
- import { getAuth , getSettings } from '../selectors' ;
12
- import SwitchRow from '../common/SwitchRow' ;
13
11
import Screen from '../common/Screen' ;
14
- import * as api from '../api' ;
15
12
import ServerPushSetupBanner from '../common/ServerPushSetupBanner' ;
16
13
import NavRow from '../common/NavRow' ;
17
14
import { IconAlertTriangle } from '../common/Icons' ;
18
15
import type { LocalizableText } from '../types' ;
19
16
import { TranslationContext } from '../boot/TranslationProvider' ;
20
17
import { kWarningColor } from '../styles/constants' ;
21
18
import { getIdentities , getIdentity , getIsActiveAccount } from '../account/accountsSelectors' ;
22
- import { getRealm , getRealmName } from '../directSelectors' ;
23
- import ZulipText from '../common/ZulipText' ;
24
- import SettingsGroup from './SettingsGroup' ;
19
+ import { getRealm } from '../directSelectors' ;
25
20
import { openSystemNotificationSettings } from '../utils/openLink' ;
26
21
import {
27
22
useNotificationReportsByIdentityKey ,
28
23
NotificationProblem ,
29
24
} from './NotifTroubleshootingScreen' ;
30
25
import { keyOfIdentity } from '../account/accountMisc' ;
26
+ import PerAccountNotificationSettingsGroup from './PerAccountNotificationSettingsGroup' ;
31
27
32
28
type Props = $ReadOnly < { |
33
29
navigation : AppNavigationProp < 'notifications' > ,
@@ -56,7 +52,6 @@ export default function NotificationsScreen(props: Props): Node {
56
52
57
53
const _ = useContext ( TranslationContext ) ;
58
54
59
- const auth = useSelector ( getAuth ) ;
60
55
const identity = useSelector ( getIdentity ) ;
61
56
const notificationReportsByIdentityKey = useNotificationReportsByIdentityKey ( ) ;
62
57
const notificationReport = notificationReportsByIdentityKey . get ( keyOfIdentity ( identity ) ) ;
@@ -67,11 +62,7 @@ export default function NotificationsScreen(props: Props): Node {
67
62
const otherAccounts = useGlobalSelector ( state =>
68
63
getIdentities ( state ) . filter ( identity_ => ! getIsActiveAccount ( state , identity_ ) ) ,
69
64
) ;
70
- const realmName = useSelector ( getRealmName ) ;
71
65
const pushNotificationsEnabled = useSelector ( state => getRealm ( state ) . pushNotificationsEnabled ) ;
72
- const offlineNotification = useSelector ( state => getSettings ( state ) . offlineNotification ) ;
73
- const onlineNotification = useSelector ( state => getSettings ( state ) . onlineNotification ) ;
74
- const streamNotification = useSelector ( state => getSettings ( state ) . streamNotification ) ;
75
66
76
67
const systemSettingsWarnings = notificationReport . problems
77
68
. map ( systemSettingsWarning )
@@ -101,37 +92,6 @@ export default function NotificationsScreen(props: Props): Node {
101
92
openSystemNotificationSettings ( ) ;
102
93
} , [ systemSettingsWarnings , _ ] ) ;
103
94
104
- const handleTroubleshootingPress = useCallback ( ( ) => {
105
- navigation . push ( 'notif-troubleshooting' ) ;
106
- } , [ navigation ] ) ;
107
-
108
- // TODO(#3999): It'd be good to show "working on it" UI feedback while a
109
- // request is pending, after the user touches a switch.
110
-
111
- const handleOfflineNotificationChange = useCallback ( ( ) => {
112
- api . toggleMobilePushSettings ( {
113
- auth,
114
- opp : 'offline_notification_change' ,
115
- value : ! offlineNotification ,
116
- } ) ;
117
- } , [ offlineNotification , auth ] ) ;
118
-
119
- const handleOnlineNotificationChange = useCallback ( ( ) => {
120
- api . toggleMobilePushSettings ( {
121
- auth,
122
- opp : 'online_notification_change' ,
123
- value : ! onlineNotification ,
124
- } ) ;
125
- } , [ onlineNotification , auth ] ) ;
126
-
127
- const handleStreamNotificationChange = useCallback ( ( ) => {
128
- api . toggleMobilePushSettings ( {
129
- auth,
130
- opp : 'stream_notification_change' ,
131
- value : ! streamNotification ,
132
- } ) ;
133
- } , [ streamNotification , auth ] ) ;
134
-
135
95
const handleOtherAccountsPress = useCallback ( ( ) => {
136
96
navigation . push ( 'account-pick' ) ;
137
97
} , [ navigation ] ) ;
@@ -166,44 +126,7 @@ export default function NotificationsScreen(props: Props): Node {
166
126
{ ! notificationReport . problems . includes ( NotificationProblem . SystemSettingsDisabled ) && (
167
127
< >
168
128
{ pushNotificationsEnabled && (
169
- < SettingsGroup
170
- title = { {
171
- text : 'Notification settings for this account ({email} in {realmName}):' ,
172
- values : {
173
- email : < ZulipText style = { { fontWeight : 'bold' } } text = { identity . email } /> ,
174
- realmName : < ZulipText style = { { fontWeight : 'bold' } } text = { realmName } /> ,
175
- } ,
176
- } }
177
- >
178
- < SwitchRow
179
- label = "Notifications when offline"
180
- value = { offlineNotification }
181
- onValueChange = { handleOfflineNotificationChange }
182
- />
183
- < SwitchRow
184
- label = "Notifications when online"
185
- value = { onlineNotification }
186
- onValueChange = { handleOnlineNotificationChange }
187
- />
188
- < SwitchRow
189
- label = "Stream notifications"
190
- value = { streamNotification }
191
- onValueChange = { handleStreamNotificationChange }
192
- />
193
- < NavRow
194
- { ...( ( ) =>
195
- notificationReport . problems . length > 0 && {
196
- leftElement : {
197
- type : 'icon' ,
198
- Component : IconAlertTriangle ,
199
- color : kWarningColor ,
200
- } ,
201
- subtitle : 'Notifications for this account may not arrive.' ,
202
- } ) ( ) }
203
- title = "Troubleshooting"
204
- onPress = { handleTroubleshootingPress }
205
- />
206
- </ SettingsGroup >
129
+ < PerAccountNotificationSettingsGroup navigation = { navigation } />
207
130
) }
208
131
{ otherAccounts . length > 0 && (
209
132
< NavRow
0 commit comments