MCPcopy Create free account
hub / github.com/codemistic/Web-Development / Book

Function Book

locallibrary/frontend/src/pages/Book.jsx:11–69  ·  view source on GitHub ↗
({theme})

Source from the content-addressed store, hash-verified

9
10// Getting request
11const 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 :&nbsp; <p>{book.title}</p></h1>
45 <strong> Author:&nbsp; <p>{book.author}</p></strong>
46 <strong> Summary: &nbsp; <p>{book.summary}</p></strong>
47 <strong> ISBN: &nbsp; <p>{book.isbn}</p></strong>
48 <strong> Genre: &nbsp; <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: &nbsp; {status_color(bookInstance.status)} </strong>
58 {bookInstance.due_back && <strong>Due to returned: &nbsp; <p>{bookInstance.due_back}</p></strong>}
59 <strong>Imprint: &nbsp; <p>{bookInstance.imprint}</p> </strong>
60 <strong>Id: &nbsp; <p>{bookInstance.id}</p> </strong>
61 </div>
62 )
63 })}
64 </div>
65 </div>
66 </div>
67 </div>
68 );

Callers

nothing calls this directly

Calls 1

status_colorFunction · 0.85

Tested by

no test coverage detected