diff --git a/src/components/shareComponent.jsx b/src/components/shareComponent.jsx index be571978..1f5f155d 100644 --- a/src/components/shareComponent.jsx +++ b/src/components/shareComponent.jsx @@ -34,29 +34,32 @@ export default class ShareComponent extends React.Component { } getUserEmails( newestGridId ){ - const gridRef = firebase.database().ref( 'grids/' + newestGridId + '/users' ); - const usersRef = firebase.database().ref( 'users/' ); - - let currentUserArray = []; - let currentUserEmails = []; + if(newestGridId !== null) + { + const gridRef = firebase.database().ref( 'grids/' + newestGridId + '/users' ); + const usersRef = firebase.database().ref( 'users/' ); - // gets keys of current grid users - gridRef.once( 'value', gridRefSnapshot => { - gridRefSnapshot.forEach( user => { - currentUserArray.push( user.key ) - } ); - } ); + let currentUserArray = []; + let currentUserEmails = []; - // retrieve emails of grid users by matching user keys with user list - usersRef.once( 'value', userSnapshot => { - userSnapshot.forEach( user => { - if( _.includes( currentUserArray, user.key ) ){ - currentUserEmails.push( user.child( 'email' ).val() ) - } - } ); - } ); + // gets keys of current grid users + gridRef.once( 'value', gridRefSnapshot => { + gridRefSnapshot.forEach( user => { + currentUserArray.push( user.key ) + } ); + } ); + + // retrieve emails of grid users by matching user keys with user list + usersRef.once( 'value', userSnapshot => { + userSnapshot.forEach( user => { + if( _.includes( currentUserArray, user.key ) ){ + currentUserEmails.push( user.child( 'email' ).val() ) + } + } ); + } ); - this.setState({ currentUsers: currentUserEmails }); + this.setState({ currentUsers: currentUserEmails }); + } } componentWillReceiveProps( nextProps ){ @@ -124,4 +127,4 @@ export default class ShareComponent extends React.Component { ); } -} \ No newline at end of file +}