Skip to content

Commit

Permalink
feat: Show notification when book moved to shelf
Browse files Browse the repository at this point in the history
Resolves: #6
  • Loading branch information
Richard Rigby committed Oct 4, 2017
1 parent 809c833 commit 96872cf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"prop-types": "^15.5.8",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-notifications": "^1.4.3",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
Expand Down
13 changes: 9 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import OpenSearchButton from './components/OpenSearchButton'
import BookShelf from './components/BookShelf'
import { Route } from 'react-router-dom'
import './App.css'
import 'react-notifications/lib/notifications.css';
import {NotificationContainer, NotificationManager} from 'react-notifications';

class BooksApp extends React.Component {
state = {
Expand Down Expand Up @@ -37,11 +39,13 @@ class BooksApp extends React.Component {
});
};

moveBook = (bookID, to) => {
moveBook = (bookID, bookTitle, toID, toName) => {
let book = { id: bookID };
BooksAPI.update(book, to).then(data => {
this.getAllBooks();
});
BooksAPI.update(book, toID).then(data => {
this.getAllBooks()
}).then(() => {
NotificationManager.success(`${bookTitle} moved to ${toName}`, 'Success!');
});;
};

render() {
Expand All @@ -66,6 +70,7 @@ class BooksApp extends React.Component {
<OpenSearchButton />
</div>
)}/>
<NotificationContainer/>
</div>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Book.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Book extends React.Component {
shelf: ""
}
moveBook = (event) => {
this.props.onMoveBook(this.props.bookID, event.target.value)
let shelfName = event.target.options[event.target.selectedIndex].text;
this.props.onMoveBook(this.props.bookID, this.props.bookTitle, event.target.value, shelfName);
};

componentDidMount() {
Expand Down
2 changes: 0 additions & 2 deletions src/components/BookShelf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class BookShelf extends React.Component {
render() {
const books = this.props.books;

console.log(books)

if (books.error === "empty query") {
return (
<div>No match found</div>
Expand Down

0 comments on commit 96872cf

Please sign in to comment.