Skip to content

Commit

Permalink
Messaging challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Esplin committed May 16, 2018
1 parent 18dab56 commit 64b015f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/messaging.js
Expand Up @@ -35,11 +35,13 @@ export class Messaging extends Component {
- See https://firebase.google.com/docs/cloud-messaging/js/receive
- Handle foreground messages
- Assign the `unlisten` function to this.unlistenOnMessage
- Call this.showMessage({ message, noteId }) to pop a snackbar message
- Hint: onMessage payload looks like { message, noteId, title }
- Hint: Share a project with your own email address to test the onMessage callback
*/
this.unlistenOnMessage = this.messaging.onMessage(payload => {
this.setState({ ...payload.data, show: true, title: 'Visit' });
});
this.unlistenOnMessage = this.messaging.onMessage(payload =>
this.showMessage(payload.data)
);
}

componentWillUnmount() {
Expand All @@ -52,6 +54,10 @@ export class Messaging extends Component {
this.props.setMessagingToken(token);
}

showMessage({ message, noteId }) {
this.setState({ message, noteId, title: 'Visit', show: true });
}

render() {
const { redirect, message, noteId, show, title } = this.state;

Expand Down

0 comments on commit 64b015f

Please sign in to comment.