Skip to content

Commit

Permalink
Add notifications after favoriting movie
Browse files Browse the repository at this point in the history
  • Loading branch information
Macxim committed Sep 9, 2017
1 parent 262c7c6 commit 3fd5a6a
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/App.js
Expand Up @@ -13,6 +13,7 @@ import Main from './components/Main';
import Discover from './components/Discover';
import SearchResults from './components/SearchResults';
import Movie from './components/Movie';
import NotificationSystem from 'react-notification-system';

import './App.css';

Expand Down Expand Up @@ -59,15 +60,45 @@ class App extends Component {
addFavoriteMovie = (selectedMovie) => {
const userUid = app.auth().currentUser.uid;

const onComplete = (error) => {
if (error) {
this._notificationSystem.addNotification({
message: 'An error ocurred.',
level: 'error'
});
} else {
this._notificationSystem.addNotification({
message: 'Movie added to favorites.',
level: 'success'
});
}
};

app.database().ref(userUid).child('favorites').update({
[selectedMovie]: selectedMovie
});
}, onComplete);


}

removeFavoriteMovie = (selectedMovie) => {
const userUid = app.auth().currentUser.uid;

app.database().ref(userUid).child('favorites').child(selectedMovie).remove();
const onComplete = (error) => {
if (error) {
this._notificationSystem.addNotification({
message: 'An error ocurred.',
level: 'error'
});
} else {
this._notificationSystem.addNotification({
message: 'Movie removed from favorites.',
level: 'success'
});
}
};

app.database().ref(userUid).child('favorites').child(selectedMovie).remove(onComplete);
}

componentWillMount = () => {
Expand Down Expand Up @@ -96,10 +127,15 @@ class App extends Component {
})
}

componentDidMount = () => {
this._notificationSystem = this.refs.notificationSystem;
}

render() {
return (
<BrowserRouter>
<div className="App">
<NotificationSystem ref="notificationSystem" />
{this.state.loading &&
<Loading />
}
Expand Down

0 comments on commit 3fd5a6a

Please sign in to comment.