Skip to content

Commit

Permalink
Merge pull request #29 from ZachLamb/fixingNullGridProblem
Browse files Browse the repository at this point in the history
fixing null grid problem by preventing sharing when gridID is null
  • Loading branch information
IanChar authored Oct 27, 2016
2 parents 89305da + 66b3c00 commit 8b38375
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/components/shareComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand Down Expand Up @@ -124,4 +127,4 @@ export default class ShareComponent extends React.Component {
</div>
);
}
}
}

0 comments on commit 8b38375

Please sign in to comment.