mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Add Vite project sample
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
import { useState } from "react";
|
||||
|
||||
const tempMovieData = [
|
||||
{
|
||||
imdbID: "tt1375666",
|
||||
Title: "Inception",
|
||||
Year: "2010",
|
||||
Poster:
|
||||
"https://m.media-amazon.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
|
||||
},
|
||||
{
|
||||
imdbID: "tt0133093",
|
||||
Title: "The Matrix",
|
||||
Year: "1999",
|
||||
Poster:
|
||||
"https://m.media-amazon.com/images/M/MV5BNzQzOTk3OTAtNDQ0Zi00ZTVkLWI0MTEtMDllZjNkYzNjNTc4L2ltYWdlXkEyXkFqcGdeQXVyNjU0OTQ0OTY@._V1_SX300.jpg",
|
||||
},
|
||||
{
|
||||
imdbID: "tt6751668",
|
||||
Title: "Parasite",
|
||||
Year: "2019",
|
||||
Poster:
|
||||
"https://m.media-amazon.com/images/M/MV5BYWZjMjk3ZTItODQ2ZC00NTY5LWE0ZDYtZTI3MjcwN2Q5NTVkXkEyXkFqcGdeQXVyODk4OTc3MTY@._V1_SX300.jpg",
|
||||
},
|
||||
];
|
||||
|
||||
const tempWatchedData = [
|
||||
{
|
||||
imdbID: "tt1375666",
|
||||
Title: "Inception",
|
||||
Year: "2010",
|
||||
Poster:
|
||||
"https://m.media-amazon.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
|
||||
runtime: 148,
|
||||
imdbRating: 8.8,
|
||||
userRating: 10,
|
||||
},
|
||||
{
|
||||
imdbID: "tt0088763",
|
||||
Title: "Back to the Future",
|
||||
Year: "1985",
|
||||
Poster:
|
||||
"https://m.media-amazon.com/images/M/MV5BZmU0M2Y1OGUtZjIxNi00ZjBkLTg1MjgtOWIyNThiZWIwYjRiXkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SX300.jpg",
|
||||
runtime: 116,
|
||||
imdbRating: 8.5,
|
||||
userRating: 9,
|
||||
},
|
||||
];
|
||||
|
||||
const average = (arr) =>
|
||||
arr.reduce((acc, cur, i, arr) => acc + cur / arr.length, 0);
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<>
|
||||
<NavBar />
|
||||
<Main />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NavBar() {
|
||||
return (
|
||||
<nav className="nav-bar">
|
||||
<Logo />
|
||||
<Search />
|
||||
<NumResults />
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
function Logo() {
|
||||
return (
|
||||
<div className="logo">
|
||||
<span role="img">🍿</span>
|
||||
<h1>usePopcorn</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Search() {
|
||||
const [query, setQuery] = useState("");
|
||||
return (
|
||||
<input
|
||||
className="search"
|
||||
type="text"
|
||||
placeholder="Search movies..."
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function NumResults() {
|
||||
return (
|
||||
<p className="num-results">
|
||||
Found <strong>X</strong> results
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
function Main() {
|
||||
return (
|
||||
<main className="main">
|
||||
<ListBox />
|
||||
<WatchedBox />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function ListBox() {
|
||||
const [isOpen1, setIsOpen1] = useState(true);
|
||||
|
||||
return (
|
||||
<div className="box">
|
||||
<button
|
||||
className="btn-toggle"
|
||||
onClick={() => setIsOpen1((open) => !open)}
|
||||
>
|
||||
{isOpen1 ? "–" : "+"}
|
||||
</button>
|
||||
{isOpen1 && <MovieList />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MovieList() {
|
||||
const [movies, setMovies] = useState(tempMovieData);
|
||||
|
||||
return (
|
||||
<ul className="list">
|
||||
{movies?.map((movie) => (
|
||||
<Movie movie={movie} key={movie.imdbID} />
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function Movie({ movie }) {
|
||||
return (
|
||||
<li key={movie.imdbID}>
|
||||
<img src={movie.Poster} alt={`${movie.Title} poster`} />
|
||||
<h3>{movie.Title}</h3>
|
||||
<div>
|
||||
<p>
|
||||
<span>🗓</span>
|
||||
<span>{movie.Year}</span>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
function WatchedBox() {
|
||||
const [watched, setWatched] = useState(tempWatchedData);
|
||||
const [isOpen2, setIsOpen2] = useState(true);
|
||||
|
||||
return (
|
||||
<div className="box">
|
||||
<button
|
||||
className="btn-toggle"
|
||||
onClick={() => setIsOpen2((open) => !open)}
|
||||
>
|
||||
{isOpen2 ? "–" : "+"}
|
||||
</button>
|
||||
{isOpen2 && (
|
||||
<>
|
||||
<WatchedSummary watched={watched} />
|
||||
<WatchMovieList watched={watched} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WatchedSummary({ watched }) {
|
||||
const avgImdbRating = average(watched.map((movie) => movie.imdbRating));
|
||||
const avgUserRating = average(watched.map((movie) => movie.userRating));
|
||||
const avgRuntime = average(watched.map((movie) => movie.runtime));
|
||||
|
||||
return (
|
||||
<div className="summary">
|
||||
<h2>Movies you watched</h2>
|
||||
<div>
|
||||
<p>
|
||||
<span>#️⃣</span>
|
||||
<span>{watched.length} movies</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>⭐️</span>
|
||||
<span>{avgImdbRating}</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>🌟</span>
|
||||
<span>{avgUserRating}</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>⏳</span>
|
||||
<span>{avgRuntime} min</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WatchMovieList({ watched }) {
|
||||
return (
|
||||
<ul className="list">
|
||||
{watched.map((movie) => (
|
||||
<WatchedMovie movie={movie} key={movie.imdbID} />
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function WatchedMovie({ movie }) {
|
||||
return (
|
||||
<li key={movie.imdbID}>
|
||||
<img src={movie.Poster} alt={`${movie.Title} poster`} />
|
||||
<h3>{movie.Title}</h3>
|
||||
<div>
|
||||
<p>
|
||||
<span>⭐️</span>
|
||||
<span>{movie.imdbRating}</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>🌟</span>
|
||||
<span>{movie.userRating}</span>
|
||||
</p>
|
||||
<p>
|
||||
<span>⏳</span>
|
||||
<span>{movie.runtime} min</span>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
:root {
|
||||
--color-primary: #6741d9;
|
||||
--color-primary-light: #7950f2;
|
||||
--color-text: #dee2e6;
|
||||
--color-text-dark: #adb5bd;
|
||||
--color-background-100: #343a40;
|
||||
--color-background-500: #2b3035;
|
||||
--color-background-900: #212529;
|
||||
--color-red: #fa5252;
|
||||
--color-red-dark: #e03131;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
|
||||
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-background-900);
|
||||
padding: 2.4rem;
|
||||
}
|
||||
|
||||
/* ******* */
|
||||
|
||||
.nav-bar {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
align-items: center;
|
||||
height: 7.2rem;
|
||||
padding: 0 3.2rem;
|
||||
background-color: var(--color-primary);
|
||||
border-radius: 0.9rem;
|
||||
}
|
||||
|
||||
.main {
|
||||
margin-top: 2.4rem;
|
||||
height: calc(100vh - 7.2rem - 3 * 2.4rem);
|
||||
display: flex;
|
||||
gap: 2.4rem;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.box {
|
||||
width: 42rem;
|
||||
max-width: 42rem;
|
||||
background-color: var(--color-background-500);
|
||||
border-radius: 0.9rem;
|
||||
/* overflow: scroll; */
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.loader {
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
margin: 4.8rem;
|
||||
}
|
||||
|
||||
.error {
|
||||
text-align: center;
|
||||
font-size: 2rem;
|
||||
padding: 4.8rem;
|
||||
}
|
||||
|
||||
/* ******* */
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.logo span {
|
||||
font-size: 3.2rem;
|
||||
}
|
||||
|
||||
.logo h1 {
|
||||
font-size: 2.4rem;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.search {
|
||||
justify-self: center;
|
||||
border: none;
|
||||
padding: 1.1rem 1.6rem;
|
||||
font-size: 1.8rem;
|
||||
border-radius: 0.7rem;
|
||||
width: 40rem;
|
||||
transition: all 0.3s;
|
||||
color: var(--color-text);
|
||||
|
||||
/* background-color: var(--color-background-900); */
|
||||
background-color: var(--color-primary-light);
|
||||
}
|
||||
|
||||
.search::placeholder {
|
||||
color: var(--color-text-dark);
|
||||
}
|
||||
|
||||
.search:focus {
|
||||
outline: none;
|
||||
box-shadow: 0 2.4rem 2.4rem rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.num-results {
|
||||
justify-self: end;
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.btn-toggle {
|
||||
position: absolute;
|
||||
top: 0.8rem;
|
||||
right: 0.8rem;
|
||||
height: 2.4rem;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background-color: var(--color-background-900);
|
||||
color: var(--color-text);
|
||||
font-size: 1.4rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.list {
|
||||
list-style: none;
|
||||
padding: 0.8rem 0;
|
||||
/* overflow: scroll; */
|
||||
}
|
||||
|
||||
.list-watched {
|
||||
height: calc(100% - 9rem);
|
||||
}
|
||||
|
||||
.list li {
|
||||
position: relative;
|
||||
display: grid;
|
||||
grid-template-columns: 4rem 1fr;
|
||||
grid-template-rows: auto auto;
|
||||
column-gap: 2.4rem;
|
||||
font-size: 1.6rem;
|
||||
align-items: center;
|
||||
|
||||
padding: 1.6rem 3.2rem;
|
||||
border-bottom: 1px solid var(--color-background-100);
|
||||
}
|
||||
|
||||
.list.list-movies li {
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.list.list-movies li:hover {
|
||||
background-color: var(--color-background-100);
|
||||
}
|
||||
|
||||
.list img {
|
||||
width: 100%;
|
||||
grid-row: 1 / -1;
|
||||
}
|
||||
|
||||
.list h3 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.list div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2.4rem;
|
||||
}
|
||||
|
||||
.list p {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.btn-delete {
|
||||
position: absolute;
|
||||
right: 2.4rem;
|
||||
|
||||
height: 1.8rem;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background-color: var(--color-red);
|
||||
color: var(--color-background-900);
|
||||
font-size: 0.9rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-delete:hover {
|
||||
background-color: var(--color-red-dark);
|
||||
}
|
||||
|
||||
/* ******* */
|
||||
|
||||
.summary {
|
||||
padding: 2.2rem 3.2rem 1.8rem 3.2rem;
|
||||
border-radius: 0.9rem;
|
||||
background-color: var(--color-background-100);
|
||||
box-shadow: 0 1.2rem 2.4rem rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.summary h2 {
|
||||
text-transform: uppercase;
|
||||
font-size: 1.6rem;
|
||||
margin-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
.summary div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2.4rem;
|
||||
font-size: 1.6rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.summary p {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
/* ******* */
|
||||
|
||||
.details {
|
||||
line-height: 1.4;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.details header {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.details section {
|
||||
padding: 4rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.6rem;
|
||||
}
|
||||
|
||||
.details img {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
.details-overview {
|
||||
width: 100%;
|
||||
padding: 2.4rem 3rem;
|
||||
background-color: var(--color-background-100);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.4rem;
|
||||
}
|
||||
|
||||
.details-overview h2 {
|
||||
font-size: 2.4rem;
|
||||
margin-bottom: 0.4rem;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.details-overview p {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.rating {
|
||||
background-color: var(--color-background-100);
|
||||
border-radius: 0.9rem;
|
||||
padding: 2rem 2.4rem;
|
||||
margin-bottom: 0.8rem;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2.4rem;
|
||||
}
|
||||
|
||||
.btn-add {
|
||||
background-color: var(--color-primary);
|
||||
color: var(--color-text);
|
||||
border: none;
|
||||
border-radius: 10rem;
|
||||
font-size: 1.4rem;
|
||||
padding: 1rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-add:hover {
|
||||
background-color: var(--color-primary-light);
|
||||
}
|
||||
|
||||
.seconds {
|
||||
background-color: var(--color-background-100);
|
||||
width: 8rem;
|
||||
border-radius: 10rem;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
padding: 0.4rem;
|
||||
margin-top: 2.4rem;
|
||||
}
|
||||
|
||||
.btn-back {
|
||||
position: absolute;
|
||||
top: 0.6rem;
|
||||
left: 0.6rem;
|
||||
height: 3.2rem;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
/* background-color: var(--color-text); */
|
||||
background-color: #fff;
|
||||
color: var(--color-background-500);
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
|
||||
font-family: sans-serif;
|
||||
font-size: 2.4rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
z-index: 999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/*
|
||||
SPACING SYSTEM (px)
|
||||
2 / 4 / 8 / 12 / 16 / 24 / 32 / 40 / 48 / 64 / 80 / 96 / 128
|
||||
|
||||
FONT SIZE SYSTEM (px)
|
||||
10 / 12 / 14 / 16 / 18 / 20 / 24 / 30 / 36 / 44 /52 / 62 / 74 / 86 / 98
|
||||
*/
|
||||
|
||||
/*
|
||||
FULL STAR
|
||||
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="#000"
|
||||
stroke="#000"
|
||||
>
|
||||
<path
|
||||
d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
|
||||
EMPTY STAR
|
||||
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="#000"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="{2}"
|
||||
d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
||||
Reference in New Issue
Block a user