Skip to content

Commit 5790a4e

Browse files
committed
NotificationsScreen: Label per-account settings as such
I could imagine someone seeing - Notifications when offline - Notifications when online - Stream notifications and wrongly thinking that they were device-level instead of account-level. So, group these per-account settings together with a header that identifies the account they apply to, with a link to the pick-account screen in case the user wants to set these values on a different account.
1 parent 5f75be0 commit 5790a4e

File tree

3 files changed

+104
-17
lines changed

3 files changed

+104
-17
lines changed

src/settings/NotificationsScreen.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import OpenNotification from 'react-native-open-notification';
77

88
import type { RouteProp } from '../react-navigation';
99
import type { AppNavigationProp } from '../nav/AppNavigator';
10-
import { useSelector } from '../react-redux';
10+
import { useGlobalSelector, useSelector } from '../react-redux';
1111
import { getAuth, getSettings } from '../selectors';
1212
import SwitchRow from '../common/SwitchRow';
1313
import Screen from '../common/Screen';
@@ -19,6 +19,10 @@ import { IconAlertTriangle } from '../common/Icons';
1919
import type { LocalizableText } from '../types';
2020
import { TranslationContext } from '../boot/TranslationProvider';
2121
import { kWarningColor } from '../styles/constants';
22+
import { getIdentities, getIdentity, getIsActiveAccount } from '../account/accountsSelectors';
23+
import { getRealmName } from '../directSelectors';
24+
import ZulipText from '../common/ZulipText';
25+
import SettingsGroup from './SettingsGroup';
2226

2327
const {
2428
ZLPConstants,
@@ -104,11 +108,22 @@ function openSystemNotificationSettings() {
104108
}
105109
}
106110

107-
/** (NB this is a per-account screen -- these are per-account settings.) */
111+
/**
112+
* Notification settings with warnings when something seems wrong.
113+
*
114+
* Includes an area for per-account settings.
115+
*/
108116
export default function NotificationsScreen(props: Props): Node {
117+
const { navigation } = props;
118+
109119
const _ = useContext(TranslationContext);
110120

111121
const auth = useSelector(getAuth);
122+
const identity = useSelector(getIdentity);
123+
const otherAccounts = useGlobalSelector(state =>
124+
getIdentities(state).filter(identity_ => !getIsActiveAccount(state, identity_)),
125+
);
126+
const realmName = useSelector(getRealmName);
112127
const offlineNotification = useSelector(state => getSettings(state).offlineNotification);
113128
const onlineNotification = useSelector(state => getSettings(state).onlineNotification);
114129
const streamNotification = useSelector(state => getSettings(state).streamNotification);
@@ -166,6 +181,10 @@ export default function NotificationsScreen(props: Props): Node {
166181
});
167182
}, [streamNotification, auth]);
168183

184+
const handleOtherAccountsPress = useCallback(() => {
185+
navigation.push('account-pick');
186+
}, [navigation]);
187+
169188
return (
170189
<Screen title="Notifications">
171190
<ServerPushSetupBanner isDismissable={false} />
@@ -194,21 +213,34 @@ export default function NotificationsScreen(props: Props): Node {
194213
})()}
195214
onPress={handleSystemSettingsPress}
196215
/>
197-
<SwitchRow
198-
label="Notifications when offline"
199-
value={offlineNotification}
200-
onValueChange={handleOfflineNotificationChange}
201-
/>
202-
<SwitchRow
203-
label="Notifications when online"
204-
value={onlineNotification}
205-
onValueChange={handleOnlineNotificationChange}
206-
/>
207-
<SwitchRow
208-
label="Stream notifications"
209-
value={streamNotification}
210-
onValueChange={handleStreamNotificationChange}
211-
/>
216+
<SettingsGroup
217+
title={{
218+
text: 'Notification settings for this account ({email} in {realmName}):',
219+
values: {
220+
email: <ZulipText style={{ fontWeight: 'bold' }} text={identity.email} />,
221+
realmName: <ZulipText style={{ fontWeight: 'bold' }} text={realmName} />,
222+
},
223+
}}
224+
>
225+
<SwitchRow
226+
label="Notifications when offline"
227+
value={offlineNotification}
228+
onValueChange={handleOfflineNotificationChange}
229+
/>
230+
<SwitchRow
231+
label="Notifications when online"
232+
value={onlineNotification}
233+
onValueChange={handleOnlineNotificationChange}
234+
/>
235+
<SwitchRow
236+
label="Stream notifications"
237+
value={streamNotification}
238+
onValueChange={handleStreamNotificationChange}
239+
/>
240+
</SettingsGroup>
241+
{otherAccounts.length > 0 && (
242+
<NestedNavRow title="Other accounts" onPress={handleOtherAccountsPress} />
243+
)}
212244
</Screen>
213245
);
214246
}

src/settings/SettingsGroup.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* @flow strict-local */
2+
3+
import * as React from 'react';
4+
import { View } from 'react-native';
5+
6+
import SwitchRow from '../common/SwitchRow';
7+
import NestedNavRow from '../common/NestedNavRow';
8+
import type { LocalizableReactText } from '../types';
9+
import { createStyleSheet } from '../styles';
10+
import { QUARTER_COLOR } from '../styles/constants';
11+
import ZulipTextIntl from '../common/ZulipTextIntl';
12+
13+
type Props = $ReadOnly<{|
14+
/**
15+
* The current style works best if this ends in a colon.
16+
*/
17+
// The need to suggest a colon is probably a sign that we can improve the
18+
// layout in some subtle way.
19+
title: LocalizableReactText,
20+
21+
children: $ReadOnlyArray<React$Element<typeof SwitchRow> | React$Element<typeof NestedNavRow>>,
22+
|}>;
23+
24+
export default function SettingsGroup(props: Props): React.Node {
25+
const { title, children } = props;
26+
27+
const styles = React.useMemo(
28+
() =>
29+
createStyleSheet({
30+
container: {
31+
overflow: 'hidden',
32+
backgroundColor: QUARTER_COLOR, // TODO: Better color
33+
marginVertical: 4,
34+
},
35+
headerContainer: {
36+
justifyContent: 'center',
37+
paddingHorizontal: 16,
38+
paddingVertical: 8,
39+
minHeight: 48,
40+
},
41+
}),
42+
[],
43+
);
44+
45+
return (
46+
<View style={styles.container}>
47+
<View style={styles.headerContainer}>
48+
<ZulipTextIntl text={title} />
49+
</View>
50+
{children}
51+
</View>
52+
);
53+
}

static/translations/messages_en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@
229229
"System settings for Zulip": "System settings for Zulip",
230230
"Notifications are disabled.": "Notifications are disabled.",
231231
"Multiple issues. Tap to learn more.": "Multiple issues. Tap to learn more.",
232+
"Notification settings for this account ({email} in {realmName}):": "Notification settings for this account ({email} in {realmName}):",
233+
"Other accounts": "Other accounts",
232234
"Notifications when online": "Notifications when online",
233235
"Notifications when offline": "Notifications when offline",
234236
"Stream notifications": "Stream notifications",

0 commit comments

Comments
 (0)