add notification settings #63

Merged
akinwale merged 2 commits from notification-settings into master 2019-10-25 17:44:50 +02:00
5 changed files with 97 additions and 6 deletions

4
package-lock.json generated
View file

@ -5640,8 +5640,8 @@
}
},
"lbry-redux": {
"version": "github:lbryio/lbry-redux#9919a8150998822ca997cd23418f023d64d4a3da",
"from": "github:lbryio/lbry-redux#9919a8150998822ca997cd23418f023d64d4a3da",
"version": "github:lbryio/lbry-redux#8ac92e3abfa0a9aacdb2fa4a144c3fadc4da6b11",
"from": "github:lbryio/lbry-redux#8ac92e3abfa0a9aacdb2fa4a144c3fadc4da6b11",
"requires": {
"proxy-polyfill": "0.1.6",
"reselect": "^3.0.0",

View file

@ -12,7 +12,7 @@
"base-64": "^0.1.0",
"@expo/vector-icons": "^8.1.0",
"gfycat-style-urls": "^1.0.3",
"lbry-redux": "lbryio/lbry-redux#9919a8150998822ca997cd23418f023d64d4a3da",
"lbry-redux": "lbryio/lbry-redux#8ac92e3abfa0a9aacdb2fa4a144c3fadc4da6b11",
"lbryinc": "lbryio/lbryinc#aebad10a9c5d725c3fedae4236d56f239a0bc1de",
"lodash": ">=4.17.11",
"merge": ">=1.2.1",

View file

@ -14,6 +14,10 @@ const select = state => ({
keepDaemonRunning: makeSelectClientSetting(SETTINGS.KEEP_DAEMON_RUNNING)(state),
showNsfw: makeSelectClientSetting(SETTINGS.SHOW_NSFW)(state),
showUriBarSuggestions: makeSelectClientSetting(SETTINGS.SHOW_URI_BAR_SUGGESTIONS)(state),
receiveSubscriptionNotifications: makeSelectClientSetting(SETTINGS.RECEIVE_SUBSCRIPTION_NOTIFICATIONS)(state),
receiveRewardNotifications: makeSelectClientSetting(SETTINGS.RECEIVE_REWARD_NOTIFICATIONS)(state),
receiveInterestsNotifications: makeSelectClientSetting(SETTINGS.RECEIVE_INTERESTS_NOTIFICATIONS)(state),
receiveCreatorNotifications: makeSelectClientSetting(SETTINGS.RECEIVE_CREATOR_NOTIFICATIONS)(state),
});
const perform = dispatch => ({

View file

@ -1,7 +1,7 @@
import React from 'react';
import { SETTINGS } from 'lbry-redux';
import { Text, View, ScrollView, Switch, NativeModules } from 'react-native';
import { navigateBack } from 'utils/helper';
import { __, navigateBack } from 'utils/helper';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import PageHeader from 'component/pageHeader';
import settingsStyle from 'styles/settings';
@ -43,6 +43,16 @@ class SettingsPage extends React.PureComponent {
}
}
setNativeBooleanSetting = (key, value) => {
const { setClientSetting } = this.props;
setClientSetting(key, value);
NativeModules.UtilityModule.setNativeBooleanSetting(key, value);
};
getBooleanSetting = (value, defaultValue) => {
return value === null || value === undefined ? defaultValue : value;
};
render() {
const {
backgroundPlayEnabled,
@ -50,14 +60,21 @@ class SettingsPage extends React.PureComponent {
keepDaemonRunning,
navigation,
popDrawerStack,
receiveSubscriptionNotifications,
receiveRewardNotifications,
receiveInterestsNotifications,
receiveCreatorNotifications,
showNsfw,
showUriBarSuggestions,
setClientSetting,
} = this.props;
// default to true if the setting is null or undefined
const actualKeepDaemonRunning =
keepDaemonRunning === null || keepDaemonRunning === undefined ? true : keepDaemonRunning;
const actualKeepDaemonRunning = this.getBooleanSetting(keepDaemonRunning, true);
const actualReceiveSubscriptionNotifications = this.getBooleanSetting(receiveSubscriptionNotifications, true);
const actualReceiveRewardNotifications = this.getBooleanSetting(receiveRewardNotifications, true);
const actualReceiveInterestsNotifications = this.getBooleanSetting(receiveInterestsNotifications, true);
const actualReceiveCreatorNotifications = this.getBooleanSetting(receiveCreatorNotifications, true);
return (
<View style={settingsStyle.container}>
@ -88,6 +105,69 @@ class SettingsPage extends React.PureComponent {
</View>
</View>
<View style={settingsStyle.sectionDivider} />
<Text style={settingsStyle.sectionTitle}>{__('Notifications')}</Text>
<Text style={settingsStyle.sectionDescription}>
{__('Choose the notifications you would like to receive.')}
</Text>
<View style={settingsStyle.row}>
<View style={settingsStyle.switchText}>
<Text style={settingsStyle.label}>{__('Subscriptions')}</Text>
</View>
<View style={settingsStyle.switchContainer}>
<Switch
value={actualReceiveSubscriptionNotifications}
onValueChange={value => {
this.setNativeBooleanSetting(SETTINGS.RECEIVE_SUBSCRIPTION_NOTIFICATIONS, value);
}}
/>
</View>
</View>
<View style={settingsStyle.row}>
<View style={settingsStyle.switchText}>
<Text style={settingsStyle.label}>{__('Rewards')}</Text>
</View>
<View style={settingsStyle.switchContainer}>
<Switch
value={actualReceiveRewardNotifications}
onValueChange={value => {
this.setNativeBooleanSetting(SETTINGS.RECEIVE_REWARD_NOTIFICATIONS, value);
}}
/>
</View>
</View>
<View style={settingsStyle.row}>
<View style={settingsStyle.switchText}>
<Text style={settingsStyle.label}>{__('Tags you follow')}</Text>
</View>
<View style={settingsStyle.switchContainer}>
<Switch
value={actualReceiveInterestsNotifications}
onValueChange={value => {
this.setNativeBooleanSetting(SETTINGS.RECEIVE_INTERESTS_NOTIFICATIONS, value);
}}
/>
</View>
</View>
{false && (
<View style={settingsStyle.row}>
<View style={settingsStyle.switchText}>
<Text style={settingsStyle.label}>{__('Content creator tips')}</Text>
</View>
<View style={settingsStyle.switchContainer}>
<Switch
value={actualReceiveCreatorNotifications}
onValueChange={value => {
kauffj commented 2019-10-24 23:02:50 +02:00 (Migrated from github.com)
Review

there's a lot of copy/paste here

there's a lot of copy/paste here
akinwale commented 2019-10-25 17:44:37 +02:00 (Migrated from github.com)
Review

I can create a component for the settings rows.

I can create a component for the settings rows.
this.setNativeBooleanSetting(SETTINGS.RECEIVE_CREATOR_NOTIFICATIONS, value);
}}
/>
</View>
</View>
)}
<View style={settingsStyle.sectionDivider} />
<Text style={settingsStyle.sectionTitle}>Search</Text>
<View style={settingsStyle.row}>

View file

@ -44,6 +44,13 @@ const settingsStyle = StyleSheet.create({
fontSize: 20,
marginBottom: 4,
},
sectionDescription: {
color: '#aaaaaa',
fontFamily: 'Inter-UI-Regular',
fontSize: 12,
lineHeight: 18,
marginBottom: 8,
},
sectionDivider: {
marginTop: 24,
},