-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restructure BookList component directory for better organiz…
…ation
- Loading branch information
Showing
12 changed files
with
59 additions
and
53 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,53 @@ | ||
// components/BookList/components/Books/Books.tsx | ||
|
||
import { useQuery } from "@apollo/client"; | ||
import { Box, Grid } from "@mui/material"; | ||
import { BOOKS_QUERY, Book } from "../../../../data/books"; | ||
import { BookCard } from "./components"; | ||
|
||
interface BooksProps { | ||
title: string; | ||
} | ||
|
||
const Message = ({ text }: { text: string }) => ( | ||
<Grid item xs={12}> | ||
<Box | ||
display="flex" | ||
height="100%" | ||
justifyContent="center" | ||
alignItems="center" | ||
> | ||
<p>{text}</p> | ||
</Box> | ||
</Grid> | ||
); | ||
|
||
export const Books = ({ title }: BooksProps) => { | ||
const { loading, error, data } = useQuery(BOOKS_QUERY, { | ||
variables: { title }, | ||
}); | ||
|
||
if (error) { | ||
console.error("Failed to fetch books:", error); | ||
return <p>Error occurred while fetching books.</p>; | ||
} | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid item xs={1} sm={1} md={2} /> | ||
<Grid item xs={10} sm={10} md={8}> | ||
<Grid container spacing={2}> | ||
{loading ? ( | ||
<Message text="Loading..." /> | ||
) : data.books.length > 0 ? ( | ||
data.books.map((book: Book) => ( | ||
<BookCard key={book.title} book={book} /> | ||
)) | ||
) : ( | ||
<Message text="No books available" /> | ||
)} | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ist/components/BookCard/BookCard.test.tsx → ...oks/components/BookCard/BookCard.test.tsx
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
export * from "./BookCard"; |
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 @@ | ||
export * from "./Books"; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./BookCard"; | ||
export * from "./Books"; |