-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
. #327
base: master
Are you sure you want to change the base?
. #327
Changes from all commits
2152a25
c3556d2
8555b85
fbf8ea9
a95c733
e611583
e64ed0b
6654702
7a71dc8
af8d429
1a29334
5d126dc
390b578
3b7e8a8
bc64bfc
0c9792a
adba813
17f62fb
fdb1ce2
d5bb1ad
c697c22
b60f68d
39441e5
7b1ca64
058a4b6
0b48994
3aff207
5100863
276a07f
d2f072e
60cea3a
485c076
7e136cc
21f746d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
# Project Movies | ||
# Project Movies 🍿🎥 | ||
|
||
Replace this readme with your own information about your project. | ||
|
||
Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
We did a movie page using react. | ||
|
||
## The problem | ||
|
||
Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
We had some problem with the intro and to upload it on netlify! | ||
|
||
## View it live | ||
|
||
Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
https://annandreas-popular-movies.netlify.app/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* /index.html 200 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<link rel="icon" type="image/png" href="%PUBLIC_URL%/favicoon.ico" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
import React from 'react'; | ||
import React from 'react' | ||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' | ||
import MovieList from 'components/MovieList' | ||
import MovieDetails from 'components/MovieDetails' | ||
import NotFound from 'components/NotFound' | ||
|
||
export const App = () => { | ||
return ( | ||
<div> | ||
Find me in src/app.js! | ||
</div> | ||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/" element={<MovieList />} /> | ||
<Route path="/details/:id" element={<MovieDetails />} /> | ||
<Route path="/404" element={<NotFound />} /> | ||
<Route path="*" element={<Navigate to="404" replace />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
|
||
); | ||
} | ||
|
||
export default App; | ||
/* BrowserRouter= Wrapper for everything / main wrapper for the whole wrap */ | ||
/* Route= Wrapper for every component */ | ||
/* Route path= Path to a single component */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
/* import React from 'react'; | ||
|
||
const Header = () => { | ||
/* const [category, setCategory] = useState('popular'); */ | ||
|
||
/* return ( | ||
<div className="header-container"> | ||
<div className="dropdown"> | ||
<button type="button">Menu</button> | ||
<div className="dropdown-content"> | ||
<a href="#">Latest</a> | ||
<a href="#">Series</a> | ||
<a href="#">Upcoming</a> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Header; | ||
*/ | ||
/* <label htmlFor="category">Change category: </label> <select id="category" onChange={(event) => | ||
setCategory(event.target.value)} value={category}> | ||
<option value="popular">Popular</option> | ||
<option value="now_playing">Now Playing</option> | ||
<option value="upcoming">Upcoming</option> | ||
<option value="top_rated">Top Rated</option> | ||
</select> */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
|
||
const Popcorn = () => ( | ||
<div className="loading-movies"> | ||
<span className="loading-intro" role="img" aria-label="loading"> | ||
|
||
<img src="https://payload.cargocollective.com/1/1/44701/13320134/New-Yorker-Movies-GIFWEB.gif" alt="popcorngif" className="center" /> | ||
<h5>Get your snacks ready</h5> | ||
</span> | ||
</div> | ||
) | ||
|
||
export default Popcorn |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
import React, { useState, useEffect } from 'react' | ||
import { useParams, useNavigate } from 'react-router-dom' | ||
import NotFound from 'components/NotFound' | ||
|
||
/* PAGE 2 */ | ||
const MovieDetails = () => { | ||
const [details, setDetails] = useState([]); | ||
const navigate = useNavigate(); | ||
const { id } = useParams() | ||
const onBackButtonClick = () => { | ||
navigate(-1); | ||
} | ||
|
||
const FetchDetails = () => { | ||
fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=e865fc7d6c1eaa875454193ac1851471&language=en-US`) | ||
.then((response) => response.json()) | ||
.then((data) => setDetails(data)) | ||
.catch((error) => { | ||
console.log(error) | ||
if (error) { | ||
return (<NotFound /> | ||
) | ||
} | ||
}) | ||
} | ||
// eslint-disable-next-line no-unused-vars | ||
const handleBackButton = (event) => { | ||
if (event.KeyCode === 13) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? Should I be able to press Enter on the backbutton? |
||
onBackButtonClick(); | ||
} | ||
}; | ||
useEffect(() => { | ||
FetchDetails() | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come you did FetchDetails as a function and not put it straight in UseEffect? |
||
|
||
return ( | ||
<section className="detail-page"> | ||
<div | ||
className="background" | ||
style={{ | ||
backgroundImage: `url(http://image.tmdb.org/t/p/original${details.backdrop_path})` | ||
}}> | ||
<div className="backbutton"> | ||
<div type="button" className="button" onClick={onBackButtonClick}> | ||
<span /> | ||
<span /> | ||
<span /> | ||
</div> | ||
</div> | ||
<div className="movie-details"> | ||
<img src={`http://image.tmdb.org/t/p/w342${details.poster_path}`} alt={details.title} /> | ||
</div> | ||
<div className="details-page-2"> | ||
<h3>{details.title} <span className="rating">⭐️{Math.round(details.vote_average * 10) / 10}</span></h3> | ||
<p>{details.overview}</p> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
export default MovieDetails; | ||
|
||
/* To round rating number to one decimal */ | ||
/* const roundedNumber = Math.round(movieDetails.vote_average * 10) / 10 */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable no-shadow */ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import Popcorn from './Intro'; | ||
/* import Header from './Header'; */ | ||
/* STARTPAGE */ | ||
const MovieList = () => { | ||
const [list, setList] = useState([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
/* Fetch function that allows us to get the movie titles, images from API */ | ||
const FetchMovies = () => { | ||
fetch('https://api.themoviedb.org/3/movie/popular?api_key=e865fc7d6c1eaa875454193ac1851471&language=en-US&page=1') | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
setList(data.results) | ||
}) | ||
} | ||
/* A call back function - this useEffect hook awakens the FetchMovies function above */ | ||
useEffect(() => { | ||
FetchMovies() | ||
setLoading(true); | ||
setTimeout(() => setLoading(false), 2000) | ||
}, []) | ||
|
||
/* This return shows the img, titles, rdate & the id on our HTML page */ | ||
return ( | ||
<section className="startPage"> | ||
{loading ? (<Popcorn />) : ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the loader! |
||
<> | ||
{/* <Header setList={setList} /> */} | ||
<div className="movie-container"> | ||
{list.map((movie) => ( | ||
<article className="movie-wrapper" key={movie.id}> | ||
<Link key={movie.id} to={`/details/${movie.id}`}> | ||
<img src={`https://image.tmdb.org/t/p/w342${movie.poster_path}`} alt={movie.title} /> | ||
<div className="details"> | ||
<h1>{movie.title}</h1> | ||
<p>Released {movie.release_date}</p> | ||
</div> | ||
</Link> | ||
</article> | ||
))} | ||
</div> | ||
</> | ||
)} | ||
</section> | ||
) | ||
} | ||
|
||
export default MovieList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const NotFound = () => { | ||
const navigate = useNavigate(); | ||
const onHomeButtonClick = () => { | ||
navigate('/'); | ||
} | ||
return ( | ||
<div> | ||
<p>Page not found</p> | ||
<button type="button" onClick={onHomeButtonClick}>Return to homepage</button> | ||
</div>); | ||
} | ||
export default NotFound; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to be consistent with the naming, so that the main function and file are named the same