Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions src/components/BookDetails/BookDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
import { useCallback, useState, useEffect } from 'react';

function BookDetails({ bookId }) {
const [bookDetails, setBookDetails] = useState(null);

const getBookDetails = useCallback(async () => {
try {
// make API call to fetch book details
const response = await fetch(`/api/books/\${bookId}`);
const data = await response.json();
// set book details in state
setBookDetails(data);
} catch (error) {
// handle error
console.error(error);
}
}, [bookId, setBookDetails]);

// call getBookDetails when component mounts
useEffect(() => {
getBookDetails();
}, [getBookDetails]);

return (
<div>
{bookDetails ? (
<div>
<h2>{bookDetails.title}</h2>
<p>Author: {bookDetails.author}</p>
<p>Genre: {bookDetails.genre}</p>
<p>Description: {bookDetails.description}</p>
</div>
) : (
<p>Loading book details...</p>
)}
</div>
);
}

export default BookDetails;
import { useCallback, useState, useEffect } from 'react';
import PropTypes from 'prop-types';

function BookDetails({ bookId }) {
const [bookDetails, setBookDetails] = useState(null);

const getBookDetails = useCallback(async () => {
try {
// make API call to fetch book details
const response = await fetch(`/api/books/${bookId}`);
const data = await response.json();
// set book details in state
setBookDetails(data);
} catch (error) {
// handle error
console.error(error);
}
}, [bookId, setBookDetails]);

// call getBookDetails when component mounts
useEffect(() => {
getBookDetails();
}, [getBookDetails]);

return (
<div>
{bookDetails ? (
<div>
<h2>{bookDetails.title}</h2>
<p>Author: {bookDetails.author}</p>
<p>Genre: {bookDetails.genre}</p>
<p>Description: {bookDetails.description}</p>
</div>
) : (
<p>Loading book details...</p>
)}
</div>
);
}

BookDetails.propTypes = {
bookId: PropTypes.number,
};
export default BookDetails;
9 changes: 8 additions & 1 deletion src/components/BookSearch/BookSearch.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import './BookSearch.css';
import SearchIcon from '@mui/icons-material/Search';
import PropTypes from 'prop-types';
import PopperPopupState from '../SearchPopup/PopupState';

function SearchWindow({ matches, filter, setFilter, isDarkMode }) {
Expand All @@ -26,4 +26,11 @@ function SearchWindow({ matches, filter, setFilter, isDarkMode }) {
);
}

SearchWindow.propTypes = {
matches: PropTypes.bool,
filter: PropTypes.string,
setFilter: PropTypes.func,
isDarkMode: PropTypes.bool,
};

export default SearchWindow;
Loading