-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: folder structure based on components
- Loading branch information
1 parent
e4defbf
commit e085706
Showing
5 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
|
||
const BookSearchForm = ({ onSubmitHandler, searchTerm, onInputChange, error }) => { | ||
return ( | ||
<form onSubmit={onSubmitHandler}> | ||
<label> | ||
<span>Search for books</span> | ||
<input | ||
type="search" | ||
placeholder="microservice, restful design, etc.," | ||
value={searchTerm} | ||
onChange={onInputChange} | ||
required | ||
/> | ||
<button type="submit">Search</button> | ||
</label> | ||
{ | ||
error && <div style={{color: `red`}}>some error occurred, while fetching api</div> | ||
} | ||
</form> | ||
); | ||
}; | ||
|
||
export default BookSearchForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import { bookAuthors } from '../utils'; | ||
|
||
const Book = ({ book }) => { | ||
return ( | ||
<li> | ||
<div> | ||
<img alt={`${book.volumeInfo.title} book`} src={`http://books.google.com/books/content?id=${book.id}&printsec=frontcover&img=1&zoom=1&source=gbs_api`} /> | ||
<div> | ||
<h3>{ book.volumeInfo.title }</h3> | ||
<p>{ bookAuthors(book.volumeInfo.authors) }</p> | ||
<p>{book.volumeInfo.publishedDate}</p> | ||
</div> | ||
</div> | ||
<hr /> | ||
</li> | ||
) | ||
}; | ||
|
||
const BooksList = ({ books }) => { | ||
return ( | ||
<ul> | ||
{ | ||
books.items.map((book, index) => { | ||
return ( | ||
<Book book={book} key={index} /> | ||
); | ||
}) | ||
} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default BooksList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
const Loader = ({ loading, searchTerm }) => { | ||
return ( | ||
<> | ||
{ | ||
loading && <div style={{color: `green`}}>fetching books for "<strong>{searchTerm}</strong>"</div> | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export default Loader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const bookAuthors = (authors) => { | ||
if (!authors) return ''; | ||
if (authors.length <= 2) { | ||
authors = authors.join(' and ') | ||
} | ||
else if (authors.length > 2) { | ||
let lastAuthor = ' and ' + authors.slice(-1); | ||
authors.pop(); | ||
authors = authors.join(', '); | ||
authors += lastAuthor; | ||
}; | ||
return authors; | ||
} |