({theme})
| 9 | |
| 10 | // Getting request |
| 11 | const Book = ({theme}) => { |
| 12 | const params = useParams(); |
| 13 | const { data: book, isLoading, isError, } = useQuery(["book"], () => { |
| 14 | return fetch(`http://127.0.0.1:8000/book/${params.id}`).then((t) =>t.json() |
| 15 | ); |
| 16 | }); |
| 17 | const { data: bookInstances } = useQuery(["bookInstance"], () => { |
| 18 | return fetch(`http://127.0.0.1:8000/book/instance/${params.id}/`).then((t) =>t.json() |
| 19 | ); |
| 20 | }); |
| 21 | |
| 22 | if (isLoading) return ( <div className="Loading"> <ReactLoading /> </div>); |
| 23 | |
| 24 | if (isError) return <h1>Error with request</h1>; |
| 25 | |
| 26 | function status_color(status) { |
| 27 | if(status === "Available"){ |
| 28 | return <p style={{color:"blue"}}>{status}</p> |
| 29 | } else if (status === "Maintenance") { |
| 30 | return <p style={{color:"yellow"}}>{status}</p> |
| 31 | } |
| 32 | else { |
| 33 | return <p style={{color:"red"}}>{status}</p> |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return ( |
| 38 | <div className="Book_container"> |
| 39 | <div> |
| 40 | <Navigation /> |
| 41 | </div> |
| 42 | <div className={`Book_div ${theme}`}> |
| 43 | <div> |
| 44 | <h1> Book : <p>{book.title}</p></h1> |
| 45 | <strong> Author: <p>{book.author}</p></strong> |
| 46 | <strong> Summary: <p>{book.summary}</p></strong> |
| 47 | <strong> ISBN: <p>{book.isbn}</p></strong> |
| 48 | <strong> Genre: <p>{book.genre[0].name}</p></strong> |
| 49 | </div> |
| 50 | <div> |
| 51 | <h1>Copies</h1> |
| 52 | <div> |
| 53 | {bookInstances?.map((bookInstance) => { |
| 54 | return ( |
| 55 | <div className={`bookInstance_container ${theme}`} key={bookInstance.id}> |
| 56 | <hr /> |
| 57 | <strong>Copy Status: {status_color(bookInstance.status)} </strong> |
| 58 | {bookInstance.due_back && <strong>Due to returned: <p>{bookInstance.due_back}</p></strong>} |
| 59 | <strong>Imprint: <p>{bookInstance.imprint}</p> </strong> |
| 60 | <strong>Id: <p>{bookInstance.id}</p> </strong> |
| 61 | </div> |
| 62 | ) |
| 63 | })} |
| 64 | </div> |
| 65 | </div> |
| 66 | </div> |
| 67 | </div> |
| 68 | ); |
nothing calls this directly
no test coverage detected