Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

notification enabled/disabled option #169

Merged
merged 4 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}))
218 changes: 123 additions & 95 deletions src/Components/Config/configBody.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react"
import React, { Component } from "react"
import {
View,
StyleSheet,
Expand All @@ -10,108 +10,138 @@ import {
Share
} from "react-native"
import { Icon } from "react-native-elements"
import firebase from "react-native-firebase"

const configBody = props => {
const { navigation } = props
return (
<View style={styles.elevationBody}>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={styles.innerBody}>
<Text style={styles.touchableStyleTitle}>Conta</Text>
<Text style={styles.line} />
<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
navigation.navigate("LanguagesScreen")
}}
>
<Icon name="language" size={28} color="#007AFF" />
<Text style={styles.touchableStyle}>Idiomas</Text>
<View style={styles.chevronStyle}>
<Icon
name="chevron-right"
size={28}
color="gray"
type="evilicon"
/>
</View>
</TouchableOpacity>
export default class configBody extends Component {
constructor() {
super()
this.state = {
switchState: false
}
this.ref = firebase
.firestore()
.collection("users")
.doc(firebase.auth().currentUser.uid)
}

<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
navigation.navigate("EditPerfilScreen")
}}
>
<Icon name="person" size={28} color="#c6056c" />
<Text style={styles.touchableStyle}>Perfil</Text>
<View style={styles.chevronStyle}>
<Icon
name="chevron-right"
size={28}
color="gray"
type="evilicon"
/>
</View>
</TouchableOpacity>
componentDidMount() {
this.ref.get().then(doc => {
const { notifications } = doc.data()
this.setState({ switchState: notifications })
})
}

<TouchableOpacity style={styles.touchableIcon}>
<Icon name="notifications" size={28} color="#ef2390" />
<Text style={styles.touchableStyle}>Notificação</Text>
<View style={styles.chevronStyle}>
<Switch />
</View>
</TouchableOpacity>
switchHandler = () => {
const { switchState } = this.state
this.ref.update({ notifications: !switchState })
this.setState(prevState => ({ switchState: !prevState.switchState }))
}

<Text style={styles.touchableStyleTitle}>Aplicativo</Text>
<Text style={styles.line} />
render() {
const { navigation } = this.props
const { switchState } = this.state
return (
<View style={styles.elevationBody}>
<ScrollView showsVerticalScrollIndicator={false}>
<View style={styles.innerBody}>
<Text style={styles.touchableStyleTitle}>Conta</Text>
<Text style={styles.line} />
<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
navigation.navigate("LanguagesScreen")
}}
>
<Icon name="language" size={28} color="#007AFF" />
<Text style={styles.touchableStyle}>Idiomas</Text>
<View style={styles.chevronStyle}>
<Icon
name="chevron-right"
size={28}
color="gray"
type="evilicon"
/>
</View>
</TouchableOpacity>

<TouchableOpacity style={styles.touchableIcon}>
<Icon name="chat" size={28} color="#e542f4" />
<Text style={styles.touchableStyle}>Enviar Feedback</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
navigation.navigate("EditPerfilScreen")
}}
>
<Icon name="person" size={28} color="#c6056c" />
<Text style={styles.touchableStyle}>Perfil</Text>
<View style={styles.chevronStyle}>
<Icon
name="chevron-right"
size={28}
color="gray"
type="evilicon"
/>
</View>
</TouchableOpacity>

<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
Share.share({
message:
"Olá, já instalou o Unichat? Se não, é bem fácil. Apenas clique no link a seguir https://github.com/ES2-UFPI/Unichat/releases"
})
}}
>
<Icon name="share" size={28} color="#14d2e8" />
<Text style={styles.touchableStyle}>Compartilhar App</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.touchableIcon}>
<Icon name="notifications" size={28} color="#ef2390" />
<Text style={styles.touchableStyle}>Notificação</Text>
<View style={styles.chevronStyle}>
<Switch
onValueChange={this.switchHandler}
value={switchState}
/>
</View>
</TouchableOpacity>

<TouchableOpacity style={styles.touchableIcon}>
<Icon name="star" size={28} color="#deea2e" />
<Text style={styles.touchableStyle}>Avaliar App</Text>
</TouchableOpacity>
<Text style={styles.touchableStyleTitle}>Aplicativo</Text>
<Text style={styles.line} />

<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
Linking.openURL(
"https://github.com/ES2-UFPI/Unichat/blob/dev/PRIVACY-POLICY.md"
)
}}
>
<Icon name="notifications" size={28} color="#25e01f" />
<Text style={styles.touchableStyle}>Política de Privacidade</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.touchableIcon}>
<Icon name="chat" size={28} color="#e542f4" />
<Text style={styles.touchableStyle}>Enviar Feedback</Text>
</TouchableOpacity>

<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
Share.share({
message:
"Olá, já instalou o Unichat? Se não, é bem fácil. Apenas clique no link a seguir https://github.com/ES2-UFPI/Unichat/releases"
})
}}
>
<Icon name="share" size={28} color="#14d2e8" />
<Text style={styles.touchableStyle}>Compartilhar App</Text>
</TouchableOpacity>

<TouchableOpacity style={styles.touchableIcon}>
<Icon name="info" size={28} color="#ef9739" />
<Text style={styles.touchableStyle}>Sobre</Text>
<TouchableOpacity style={styles.touchableIcon}>
<Icon name="star" size={28} color="#deea2e" />
<Text style={styles.touchableStyle}>Avaliar App</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.touchableIcon}
onPress={() => {
Linking.openURL(
"https://github.com/ES2-UFPI/Unichat/blob/dev/PRIVACY-POLICY.md"
)
}}
>
<Icon name="notifications" size={28} color="#25e01f" />
<Text style={styles.touchableStyle}>Política de Privacidade</Text>
</TouchableOpacity>

<TouchableOpacity style={styles.touchableIcon}>
<Icon name="info" size={28} color="#ef9739" />
<Text style={styles.touchableStyle}>Sobre</Text>
</TouchableOpacity>
</View>
<TouchableOpacity>
<Text style={styles.touchableStyleExit}>Excluir Conta</Text>
</TouchableOpacity>
</View>
<TouchableOpacity>
<Text style={styles.touchableStyleExit}>Excluir Conta</Text>
</TouchableOpacity>
</ScrollView>
</View>
)
</ScrollView>
</View>
)
}
}

const styles = StyleSheet.create({
Expand Down Expand Up @@ -169,5 +199,3 @@ const styles = StyleSheet.create({
marginRight: 20
}
})

export default configBody
3 changes: 2 additions & 1 deletion src/Screens/PerfilSettings/perfilsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export default class PerfilSettings extends Component {
language_code: code,
profile_img_url: profileImageUrl,
online: true,
lastSeen: ""
lastSeen: "",
notifications: true
})
})
}
Expand Down