swapi
This commit is contained in:
parent
c7b46dadc3
commit
982d8d4393
6
http-sw/.prettierrc.json
Normal file
6
http-sw/.prettierrc.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 4,
|
||||
"semi": false,
|
||||
"singleQuote": false
|
||||
}
|
35048
http-sw/package-lock.json
generated
Normal file
35048
http-sw/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
http-sw/package.json
Normal file
34
http-sw/package.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "react-the-complete-guide",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.4.1",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"react-scripts": "3.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
BIN
http-sw/public/favicon.ico
Normal file
BIN
http-sw/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
43
http-sw/public/index.html
Normal file
43
http-sw/public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
BIN
http-sw/public/logo192.png
Normal file
BIN
http-sw/public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
http-sw/public/logo512.png
Normal file
BIN
http-sw/public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
http-sw/public/manifest.json
Normal file
25
http-sw/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
http-sw/public/robots.txt
Normal file
3
http-sw/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
29
http-sw/src/App.css
Normal file
29
http-sw/src/App.css
Normal file
@ -0,0 +1,29 @@
|
||||
section {
|
||||
margin: 1rem auto;
|
||||
width: 90%;
|
||||
max-width: 40rem;
|
||||
text-align: center;
|
||||
background-color: white;
|
||||
padding: 2rem;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
background: #230052;
|
||||
border: 1px solid #230052;
|
||||
color: white;
|
||||
padding: 0.75rem 2rem;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
button:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button:hover,
|
||||
button:active {
|
||||
background-color: #460897;
|
||||
border-color: #460897;
|
||||
}
|
64
http-sw/src/App.js
Normal file
64
http-sw/src/App.js
Normal file
@ -0,0 +1,64 @@
|
||||
import React, { useState } from "react"
|
||||
|
||||
import MoviesList from "./components/MoviesList"
|
||||
import "./App.css"
|
||||
|
||||
function App() {
|
||||
const [movies, setMovies] = useState([])
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
const fetchMoviesHandler = async () => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
const response = await fetch("https://swapi.dev/api/films/")
|
||||
if (!response.ok) {
|
||||
throw new Error(`something went wrong ${response.status}`)
|
||||
}
|
||||
const data = await response.json()
|
||||
|
||||
setIsLoading(false)
|
||||
|
||||
const transformedMovies = data.results.map((movieData) => {
|
||||
return {
|
||||
id: movieData.episode_id,
|
||||
title: movieData.title,
|
||||
openingText: movieData.opening_crawl,
|
||||
releaseDate: movieData.release_date,
|
||||
}
|
||||
})
|
||||
|
||||
setMovies(transformedMovies)
|
||||
} catch (error) {
|
||||
setError(error.message)
|
||||
}
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
let content = <p>Found no movies.</p>
|
||||
if (movies.length > 0) {
|
||||
content = <MoviesList movies={movies} />
|
||||
}
|
||||
if (error) {
|
||||
content = <p>{error}</p>
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
content = <p>Loading...</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<section>
|
||||
<button onClick={fetchMoviesHandler}>Fetch Movies</button>
|
||||
</section>
|
||||
<section>
|
||||
{content}
|
||||
</section>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
15
http-sw/src/components/Movie.js
Normal file
15
http-sw/src/components/Movie.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
|
||||
import classes from './Movie.module.css';
|
||||
|
||||
const Movie = (props) => {
|
||||
return (
|
||||
<li className={classes.movie}>
|
||||
<h2>{props.title}</h2>
|
||||
<h3>{props.releaseDate}</h3>
|
||||
<p>{props.openingText}</p>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
export default Movie;
|
20
http-sw/src/components/Movie.module.css
Normal file
20
http-sw/src/components/Movie.module.css
Normal file
@ -0,0 +1,20 @@
|
||||
.movie {
|
||||
margin: 1rem;
|
||||
padding: 1rem;
|
||||
background-color: #230052;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
|
||||
border-radius: 12px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.movie h2 {
|
||||
font-size: 2rem;
|
||||
color: #f7e702;
|
||||
}
|
||||
|
||||
.movie h3 {
|
||||
color: #eccf77;
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
21
http-sw/src/components/MoviesList.js
Normal file
21
http-sw/src/components/MoviesList.js
Normal file
@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
|
||||
import Movie from './Movie';
|
||||
import classes from './MoviesList.module.css';
|
||||
|
||||
const MovieList = (props) => {
|
||||
return (
|
||||
<ul className={classes['movies-list']}>
|
||||
{props.movies.map((movie) => (
|
||||
<Movie
|
||||
key={movie.id}
|
||||
title={movie.title}
|
||||
releaseDate={movie.releaseDate}
|
||||
openingText={movie.openingText}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export default MovieList;
|
5
http-sw/src/components/MoviesList.module.css
Normal file
5
http-sw/src/components/MoviesList.module.css
Normal file
@ -0,0 +1,5 @@
|
||||
.movies-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
12
http-sw/src/index.css
Normal file
12
http-sw/src/index.css
Normal file
@ -0,0 +1,12 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: #272727;
|
||||
}
|
8
http-sw/src/index.js
Normal file
8
http-sw/src/index.js
Normal file
@ -0,0 +1,8 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(<App />);
|
Loading…
Reference in New Issue
Block a user