From ae3d062b082d77c0da2269dee7eb2f9a4a5714ad Mon Sep 17 00:00:00 2001 From: Neto Chaves Date: Wed, 29 May 2019 13:18:49 -0300 Subject: [PATCH 1/2] notification enabled/disabled option --- functions/index.js | 6 +- src/Components/Config/configBody.js | 189 +++++++++++-------- src/Screens/PerfilSettings/perfilsettings.js | 3 +- 3 files changed, 115 insertions(+), 83 deletions(-) diff --git a/functions/index.js b/functions/index.js index ca0ad9a..ce7223f 100644 --- a/functions/index.js +++ b/functions/index.js @@ -45,8 +45,10 @@ return (exports.sendPushNotification = functions.firestore .doc(userId) .get() .then(doc => { - const { pushToken } = doc.data() - return admin.messaging().sendToDevice(pushToken, payload) + const { pushToken, notifications } = doc.data() + if (notifications) + return admin.messaging().sendToDevice(pushToken, payload) + else return null }) } })) diff --git a/src/Components/Config/configBody.js b/src/Components/Config/configBody.js index 888953a..57fabe7 100644 --- a/src/Components/Config/configBody.js +++ b/src/Components/Config/configBody.js @@ -1,4 +1,4 @@ -import React from "react" +import React, { Component } from "react" import { View, StyleSheet, @@ -8,93 +8,124 @@ import { Switch } from "react-native" import { Icon } from "react-native-elements" +import firebase from "react-native-firebase" -const configBody = props => { - const { navigation } = props - return ( - - - - Conta - - { - navigation.navigate("LanguagesScreen") - }} - > - - Idiomas - - - - +export default class configBody extends Component { + constructor() { + super() + this.state = { + switchState: false + } + this.ref = firebase + .firestore() + .collection("users") + .doc(firebase.auth().currentUser.uid) + } - { - navigation.navigate("EditPerfilScreen") - }} - > - - Perfil - - - - + componentDidMount() { + this.ref.get().then(doc => { + const { notifications } = doc.data() + this.setState({ switchState: notifications }) + }) + } - - - Notificação - - - - + switchHandler = () => { + const { switchState } = this.state + this.ref.update({ notifications: !switchState }) + this.setState(prevState => ({ switchState: !prevState.switchState })) + } - Aplicativo - + render() { + const { navigation } = this.props + const { switchState } = this.state + return ( + + + + Conta + + { + navigation.navigate("LanguagesScreen") + }} + > + + Idiomas + + + + - - - Enviar Feedback - + { + navigation.navigate("EditPerfilScreen") + }} + > + + Perfil + + + + - - - Compartilhar App - + + + Notificação + + + + - - - Avaliar App - + Aplicativo + - - - Política de Privacidade - + + + Enviar Feedback + + + + + Compartilhar App + + + + + Avaliar App + - - - Sobre + + + Política de Privacidade + + + + + Sobre + + + + Excluir Conta - - - Excluir Conta - - - - ) + + + ) + } } const styles = StyleSheet.create({ @@ -152,5 +183,3 @@ const styles = StyleSheet.create({ marginRight: 20 } }) - -export default configBody diff --git a/src/Screens/PerfilSettings/perfilsettings.js b/src/Screens/PerfilSettings/perfilsettings.js index e8ce721..0fdd8f7 100644 --- a/src/Screens/PerfilSettings/perfilsettings.js +++ b/src/Screens/PerfilSettings/perfilsettings.js @@ -73,7 +73,8 @@ export default class PerfilSettings extends Component { language_code: code, profile_img_url: profileImageUrl, online: true, - lastSeen: "" + lastSeen: "", + notifications: true }) }) } From a7ced9cdc44594589d6f22df1fe47fda825c2510 Mon Sep 17 00:00:00 2001 From: Neto Chaves Date: Sat, 1 Jun 2019 18:59:40 -0300 Subject: [PATCH 2/2] fiz error --- src/Components/Config/configBody.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Components/Config/configBody.js b/src/Components/Config/configBody.js index d414de1..b8d2aae 100644 --- a/src/Components/Config/configBody.js +++ b/src/Components/Config/configBody.js @@ -130,11 +130,6 @@ export default class configBody extends Component { Política de Privacidade - - - Política de Privacidade - - Sobre