working on assignment-4
This commit is contained in:
parent
91fe3e6e5b
commit
5c1d55412b
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
8
README copy.md
Normal file
8
README copy.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# React + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
38
eslint.config.js
Normal file
38
eslint.config.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import react from 'eslint-plugin-react'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
|
||||
export default [
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
files: ['**/*.{js,jsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
ecmaFeatures: { jsx: true },
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
settings: { react: { version: '18.3' } },
|
||||
plugins: {
|
||||
react,
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...js.configs.recommended.rules,
|
||||
...react.configs.recommended.rules,
|
||||
...react.configs['jsx-runtime'].rules,
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react/jsx-no-target-blank': 'off',
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
13
index.html
Normal file
13
index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
5714
package-lock.json
generated
Normal file
5714
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
34
package.json
Normal file
34
package.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "star-wars",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router": "^6.28.1",
|
||||
"react-router-dom": "^6.28.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@types/react": "^18.3.18",
|
||||
"@types/react-dom": "^18.3.5",
|
||||
"@vitejs/plugin-react-swc": "^3.5.0",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"eslint": "^9.17.0",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.16",
|
||||
"globals": "^15.14.0",
|
||||
"postcss": "^8.4.49",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"vite": "^6.0.5"
|
||||
}
|
||||
}
|
6
postcss.config.js
Normal file
6
postcss.config.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
BIN
public/images/logo.png
Normal file
BIN
public/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
109
src/App.css
Normal file
109
src/App.css
Normal file
|
@ -0,0 +1,109 @@
|
|||
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap");
|
||||
|
||||
body {
|
||||
background-color: #000;
|
||||
font-family: "Poppins", sans-serif;
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.main {
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header img {
|
||||
width: 200px;
|
||||
animation: fadeIn 2s ease-in-out;
|
||||
}
|
||||
|
||||
.character-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.character-card {
|
||||
background-color: #111;
|
||||
border: 2px solid #ffcc00;
|
||||
border-radius: 10px;
|
||||
width: 250px;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
transition: transform 0.3s, box-shadow 0.3s;
|
||||
}
|
||||
|
||||
.character-card:hover {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 5px 15px rgba(255, 204, 0, 0.5);
|
||||
}
|
||||
|
||||
.character-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.character-details p {
|
||||
margin: 10px 0;
|
||||
color: #ffcc00;
|
||||
}
|
||||
|
||||
.changePage {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.button {
|
||||
background-color: #ffcc00;
|
||||
color: #000;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
margin: 0 10px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #ffb103;
|
||||
}
|
||||
|
||||
.loading {
|
||||
font-size: 24px;
|
||||
color: #ffcc00;
|
||||
animation: pulse 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 0.8;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.character-card {
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.button {
|
||||
width: 100px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
38
src/App.jsx
Normal file
38
src/App.jsx
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
||||
import "./App.css";
|
||||
import Home from "./pages/Home";
|
||||
import About from "./pages/About";
|
||||
import Contact from "./pages/Contact";
|
||||
import Layout from "./components/layout/Layout";
|
||||
import Error from "./components/Error";
|
||||
function App() {
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <Layout />,
|
||||
errorElement: <Error />,
|
||||
children: [
|
||||
{
|
||||
path: "/about",
|
||||
element: <About />,
|
||||
},
|
||||
{
|
||||
path: "/contact",
|
||||
element: <Contact />,
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
element: <Home />,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<RouterProvider router={router} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
28
src/components/CharacterCard.jsx
Normal file
28
src/components/CharacterCard.jsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
import React from "react";
|
||||
import "../App.css";
|
||||
|
||||
const CharacterCard = (props) => {
|
||||
return (
|
||||
<ul className="character-container">
|
||||
{props.data.map((character, index) => (
|
||||
<li className="character-card" key={index}>
|
||||
<img
|
||||
src={`https://starwars-visualguide.com/assets/img/characters/${index +
|
||||
1}.jpg`}
|
||||
alt={character.name}
|
||||
className="character-image"
|
||||
/>
|
||||
<div className="character-details">
|
||||
<p>Name: {character.name}</p>
|
||||
<p>Height: {character.height} cm</p>
|
||||
<p>Mass: {character.mass} kg</p>
|
||||
<p>Hair Color: {character.hair_color}</p>
|
||||
<p>Birth Year: {character.birth_year}</p>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export default CharacterCard;
|
16
src/components/Error.jsx
Normal file
16
src/components/Error.jsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import React from "react";
|
||||
import { Link, useRouteError } from "react-router-dom";
|
||||
const Error = () => {
|
||||
const error = useRouteError();
|
||||
return (
|
||||
<div>
|
||||
<h1>OOPS! An error occured. </h1>
|
||||
<p>{error.data} </p>
|
||||
<Link to="/">
|
||||
<button> Go Home </button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Error;
|
26
src/components/Film.jsx
Normal file
26
src/components/Film.jsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import axios from "axios";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import "../App.css";
|
||||
const Film = () => {
|
||||
const [data, setData] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
axios.get(`https://swapi.py4e.com/api/films/`).then((res) => {
|
||||
setData(res.data.results);
|
||||
console.log(res.data.results);
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<ul>
|
||||
{data.map((elem, index) => {
|
||||
return (
|
||||
<li id="movieStyle" key={index}>
|
||||
<p>Movie Title : {elem.title}</p>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export default Film;
|
11
src/components/Footer.jsx
Normal file
11
src/components/Footer.jsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
|
||||
const Footer = () => {
|
||||
return (
|
||||
<div>
|
||||
footer
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Footer
|
7
src/components/Navbar.jsx
Normal file
7
src/components/Navbar.jsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
import React from "react";
|
||||
|
||||
const Navbar = () => {
|
||||
return <div>navbar</div>;
|
||||
};
|
||||
|
||||
export default Navbar;
|
15
src/components/layout/Layout.jsx
Normal file
15
src/components/layout/Layout.jsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import React from 'react'
|
||||
import { Outlet } from 'react-router'
|
||||
import Navbar from '../Navbar'
|
||||
import Footer from '../Footer'
|
||||
const Layout = () => {
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
<Outlet />
|
||||
<Footer />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Layout;
|
3
src/index.css
Normal file
3
src/index.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
10
src/main.jsx
Normal file
10
src/main.jsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
11
src/pages/About.jsx
Normal file
11
src/pages/About.jsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
|
||||
const About = () => {
|
||||
return (
|
||||
<div>
|
||||
about page
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default About
|
11
src/pages/Contact.jsx
Normal file
11
src/pages/Contact.jsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
|
||||
const Contact = () => {
|
||||
return (
|
||||
<div>
|
||||
contact page
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Contact
|
47
src/pages/Home.jsx
Normal file
47
src/pages/Home.jsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import axios from "axios";
|
||||
import CharacterCard from "../components/CharacterCard";
|
||||
|
||||
const Home = () => {
|
||||
const [page, setPage] = useState(1);
|
||||
const [data, setData] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const increment = () => {
|
||||
setPage(page + 1);
|
||||
};
|
||||
|
||||
const decrement = () => {
|
||||
setPage(page - 1);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
axios.get(`https://swapi.py4e.com/api/people/?page=${page}`).then((res) => {
|
||||
setData(res.data.results);
|
||||
setLoading(false);
|
||||
});
|
||||
}, [page]);
|
||||
|
||||
return (
|
||||
<div className="main">
|
||||
<div className="header">
|
||||
<img src="/images/logo.png" alt="Logo" />
|
||||
</div>
|
||||
|
||||
{loading ? <p className="loading">Loading...</p> : <CharacterCard data={data} />}
|
||||
{!loading && <div className="showPage">Page: {page}</div>}
|
||||
|
||||
<div className="changePage">
|
||||
<button className="button" disabled={page === 1} onClick={decrement}>
|
||||
Previous
|
||||
</button>
|
||||
<button className="button" onClick={increment}>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Home;
|
12
tailwind.config.js
Normal file
12
tailwind.config.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
"./index.html",
|
||||
"./src/**/*.{js,ts,jsx,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
7
vite.config.js
Normal file
7
vite.config.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
Loading…
Reference in a new issue