diff --git a/src/App.css b/src/App.css index 8ee0f1b..683a976 100644 --- a/src/App.css +++ b/src/App.css @@ -15,6 +15,8 @@ body { .header img { width: 200px; + height: 200px; + margin: auto; animation: fadeIn 2s ease-in-out; } @@ -23,6 +25,7 @@ body { flex-wrap: wrap; justify-content: center; gap: 20px; + cursor: pointer; } .character-card { @@ -89,7 +92,8 @@ body { } @keyframes pulse { - 0%, 100% { + 0%, + 100% { opacity: 0.8; } 50% { diff --git a/src/App.jsx b/src/App.jsx index b73a1e2..0284122 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -5,6 +5,7 @@ import About from "./pages/About"; import Contact from "./pages/Contact"; import Layout from "./components/layout/Layout"; import Error from "./components/Error"; +import CharacterDetails from "./components/CharacterDetails"; function App() { const router = createBrowserRouter([ { @@ -24,6 +25,11 @@ function App() { path: "/", element: , }, + { + path: "/characterDetails/:id", + + element: , + }, ], }, ]); diff --git a/src/components/CharacterCard.jsx b/src/components/CharacterCard.jsx index afa3509..99a4f40 100644 --- a/src/components/CharacterCard.jsx +++ b/src/components/CharacterCard.jsx @@ -1,26 +1,27 @@ import React from "react"; import "../App.css"; +import { Link } from "react-router-dom"; const CharacterCard = (props) => { return ( ); }; diff --git a/src/components/CharacterDetails.jsx b/src/components/CharacterDetails.jsx new file mode 100644 index 0000000..528d083 --- /dev/null +++ b/src/components/CharacterDetails.jsx @@ -0,0 +1,61 @@ +import axios from "axios"; +import React, { useEffect, useState } from "react"; +import { useParams } from "react-router"; +const CharacterDetails = () => { + const { id } = useParams(); + console.log(id); + const [character, setCharacter] = useState(null); + const [loading, setLoading] = useState(false); + + useEffect(() => { + setLoading(true); + axios + .get(`https://swapi.py4e.com/api/people/${id}/`) + .then((res) => { + setCharacter(res.data); + setLoading(false); + }) + .catch((err) => { + console.log(err); + }); + }, []); + + if (loading) { + return

loading...

; + } + + if (!character) { + return

Character Details not found!

; + } + + return ( +
+

{character.name}

+

+ Gender: + {character.gender} +

+

+ Home World: + {character.homeworld} +

+

+ Species: {character.species} +

+

+ Films: {character.films} +

+

+ Height: {character.height} cm +

+

+ Hair Color: {character.hair_color} +

+

+ Birth Year: {character.birth_year} +

+
+ ); +}; + +export default CharacterDetails;