Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getAvatar(){
var that = this
getFirestore().collection('users').doc(this.props.author).get()
.then(function(doc) {
if (doc.exists) {
if(doc.data().photoURL !== undefined){
that.setState({
photoURL: doc.data().photoURL
})
}else{
that.setState({
photoURL: null
})
}
} else {
// doc.data() will be undefined in this case
message.error("No such document!");
}
}).catch(function(error) {
userLiked: true,
amountOfLikes: this.state.amountOfLikes + 1
})
getFirestore().collection('stories').doc(this.props.id).update({
likes: firebase.firestore.FieldValue.arrayUnion(
this.props.auth.displayName
),
likeCount: firebase.firestore.FieldValue.increment(1)
})
}else{
this.setState({
userLiked: false,
amountOfLikes: this.state.amountOfLikes - 1
})
// Delete user from posts 'likes' collection
getFirestore().collection('stories').doc(this.props.id).update({
likes: firebase.firestore.FieldValue.arrayRemove(
this.props.auth.displayName
),
likeCount: firebase.firestore.FieldValue.increment(-1)
})
}
}else{
message.warning('Please login or sign up to like prompts')
}
}
return (dispatch, getState, {getFirebase}) => {
const firebase = getFirebase();
const firestore = getFirestore();
let check = false;
let usersRef = firestore.collection('users');
usersRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
if (doc.id === newUser.username) { check = true; }
});
if (check === false) {
firebase.auth().createUserWithEmailAndPassword(
newUser.email,
newUser.password,
).then((resp) => {
return (
firestore.collection('users').doc(newUser.username).set({
uid: resp.user.uid,
displayName: newUser.username
deleteSubmission(){
getFirestore().collection('stories').doc(this.props.postId).collection('submissions').doc(this.props.id).delete()
.then(function() {
message.success('Your submission has been deleted.')
}).catch(function(error) {
message.error(error)
});
}
getAvatar(){
var that = this
getFirestore().collection('users').doc(this.props.author).get()
.then(function(doc) {
if (doc.exists) {
if(doc.data().photoURL !== undefined){
that.setState({
photoURL: doc.data().photoURL
})
}else{
that.setState({
photoURL: null
})
}
} else {
message.error("No such document!");
}
}).catch(function(error) {
message.error("Error getting document:", error);
getFirestore().collection('notifications').doc().set({
title: this.props.title,
notification: 'is now on chapter ' + (this.props.currentChapter + 1),
type: 'chapter',
id: this.props.id,
time: now.toString(),
date: now
})
}else{
getFirestore().collection('stories').doc(this.props.id).update({
complete: true,
selectedChapters: firebase.firestore.FieldValue.arrayUnion(
topSubmission
)
})
getFirestore().collection('notifications').doc().set({
title: this.props.title,
notification: 'has been completed',
type: 'complete',
id: this.props.id,
time: now.toString(),
date: now
})
}
}
handleReport = e => {
var text = this.state.text
var value = this.state.value
if(value === null){
message.error('Please select a type')
}else if(text.length === 0){
message.error('Please provide reasoning')
}else{
getFirestore().collection('reports').doc().set({
postId: this.props.id,
type: this.props.type,
category: value,
reason: text
})
this.setState({
visible: false
},() => {
if(this.type === "story"){
message.success("Story has been reported! We'll look into it")
}else{
message.success("Prompt has been reported! We'll look into it")
}
})
}
};
getAvatar(displayName){
var that = this
getFirestore().collection('users').doc(displayName).get()
.then(function(doc) {
if (doc.exists) {
if(doc.data().photoURL !== undefined){
that.setState({
photoURL: doc.data().photoURL
})
}else{
that.setState({
photoURL: null
})
}
}
}).catch(function(error) {
message.error("Error getting document:", error);
});
}
getAvatar(){
var that = this
if(this.props.auth.displayName !== null){
getFirestore().collection('users').doc(this.props.auth.displayName).get()
.then(function(doc) {
if (doc.exists) {
if(doc.data().photoURL !== undefined){
that.setState({
photoURL: doc.data().photoURL
})
}else{
that.setState({
photoURL: null
})
}
} else {
message.error('Pic does not exist')
}
}).catch(function(error) {
message.error(error)