()
| 10 | |
| 11 | // Getting request |
| 12 | const Author = () => { |
| 13 | const params = useParams(); |
| 14 | |
| 15 | const { data: author, isLoading, isError, } = useQuery(["author"], () => { |
| 16 | return fetch(`http://127.0.0.1:8000/author/${params.id}`).then( (t) => t.json()); |
| 17 | }); |
| 18 | |
| 19 | const { data: authorBooks } = useQuery(["authorBooks"], () => { |
| 20 | return fetch(`http://127.0.0.1:8000/author/books/${params.id}`).then((t) => t.json()); |
| 21 | }); |
| 22 | |
| 23 | if (isLoading) |
| 24 | return ( <div className="Loading"> <ReactLoading /> </div>); |
| 25 | |
| 26 | if (isError) return <h1>Error with request</h1>; |
| 27 | |
| 28 | return ( |
| 29 | <div className="Author_continer"> |
| 30 | <div> <Navigation /> </div> |
| 31 | <div className="Author_div"> |
| 32 | <h1> Author: {author.first_name} {author.last_name} </h1> |
| 33 | <p> |
| 34 | {author.date_of_birth} <i style={{ color: "red" }}>to</i>{" "} |
| 35 | {author.date_of_death ? "💀" + author.date_of_death : "😃"} |
| 36 | </p> |
| 37 | <h2>Books</h2> |
| 38 | <div> |
| 39 | {authorBooks?.map((authorBook) => { |
| 40 | return ( |
| 41 | <div className="author_list-container" key={authorBook.id}> |
| 42 | <ul> |
| 43 | <Link to={"/Book/" + authorBook.id}> |
| 44 | <li> <p>{authorBook.title}</p> </li> |
| 45 | </Link> |
| 46 | </ul> |
| 47 | </div> |
| 48 | ); |
| 49 | })} |
| 50 | </div> |
| 51 | </div> |
| 52 | </div> |
| 53 | ); |
| 54 | }; |
| 55 | |
| 56 | export default Author; |
nothing calls this directly
no outgoing calls
no test coverage detected