From 61f0aa5dacb06faa5f158ab6d56873c49cd977ea Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 25 Oct 2019 16:44:49 +0100 Subject: [PATCH] add notification settings (#63) --- package-lock.json | 4 +- package.json | 2 +- src/page/settings/index.js | 4 ++ src/page/settings/view.js | 86 ++++++++++++++++++++++++++++++++++++-- src/styles/settings.js | 7 ++++ 5 files changed, 97 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index d48c43a..9959697 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 4537222..34c95c0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/page/settings/index.js b/src/page/settings/index.js index c90d2d5..b36796a 100644 --- a/src/page/settings/index.js +++ b/src/page/settings/index.js @@ -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 => ({ diff --git a/src/page/settings/view.js b/src/page/settings/view.js index 659fe72..ffeb6fe 100644 --- a/src/page/settings/view.js +++ b/src/page/settings/view.js @@ -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 ( @@ -88,6 +105,69 @@ class SettingsPage extends React.PureComponent { + + {__('Notifications')} + + {__('Choose the notifications you would like to receive.')} + + + + {__('Subscriptions')} + + + { + this.setNativeBooleanSetting(SETTINGS.RECEIVE_SUBSCRIPTION_NOTIFICATIONS, value); + }} + /> + + + + + + {__('Rewards')} + + + { + this.setNativeBooleanSetting(SETTINGS.RECEIVE_REWARD_NOTIFICATIONS, value); + }} + /> + + + + + + {__('Tags you follow')} + + + { + this.setNativeBooleanSetting(SETTINGS.RECEIVE_INTERESTS_NOTIFICATIONS, value); + }} + /> + + + + {false && ( + + + {__('Content creator tips')} + + + { + this.setNativeBooleanSetting(SETTINGS.RECEIVE_CREATOR_NOTIFICATIONS, value); + }} + /> + + + )} + Search diff --git a/src/styles/settings.js b/src/styles/settings.js index adcc434..4e32797 100644 --- a/src/styles/settings.js +++ b/src/styles/settings.js @@ -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, },