-
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
Oscar and Regina's Project Movies #325
base: master
Are you sure you want to change the base?
Changes from all commits
2df561e
ce8fdc1
d50b7e7
39b6162
288afdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,29 @@ | ||
import React from 'react'; | ||
/* eslint-disable linebreak-style */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||
import { PopularList } from './components/PopularList.js' | ||
import { ShowMovie } from './components/ShowMovie' | ||
|
||
export const App = () => { | ||
const [list, setList] = useState([]); | ||
|
||
useEffect(() => { | ||
fetch('https://api.themoviedb.org/3/movie/popular?api_key=5b17ba21606be74c35e11124051ec659&language=en-US&page=1') | ||
.then((response) => response.json()) | ||
.then((data) => setList(data.results)) | ||
.catch((error) => console.error(error)) | ||
.finally(() => console.log('movie list')) | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
Find me in src/app.js! | ||
</div> | ||
<BrowserRouter> | ||
<main> | ||
<Routes> | ||
<Route path="/" element={<PopularList movies={list} />} /> | ||
<Route path="/showmovie/:id" element={<ShowMovie />} /> | ||
</Routes> | ||
</main> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable linebreak-style */ | ||
import React from 'react' | ||
import { Link } from 'react-router-dom' | ||
|
||
export const PopularList = ({ movies }) => { | ||
return ( | ||
<section className="all-movies"> | ||
{movies.map((movie) => { | ||
return ( | ||
<div className="movie-container"> | ||
<Link | ||
key={movie.id} | ||
to={`/showmovie/${movie.id}`} | ||
className="movie"> | ||
<div className="img-overlay" /> | ||
<img className="all-movie-posters" src={`https://image.tmdb.org/t/p/w342/${movie.poster_path}`} alt="poster" /> | ||
<div className="movie-info"> | ||
<h1>{movie.title}</h1> | ||
<p>Release date: {movie.release_date}</p> | ||
</div> | ||
</Link> | ||
</div> | ||
) | ||
})} | ||
</section> | ||
) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable linebreak-style */ | ||
import React, { useState, useEffect } from 'react' | ||
import { useNavigate, useParams } from 'react-router-dom' | ||
|
||
export const ShowMovie = () => { | ||
const [details, setDetails] = useState([]) | ||
const navigate = useNavigate() | ||
const { id } = useParams() | ||
|
||
useEffect(() => { | ||
fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=5b17ba21606be74c35e11124051ec659`) | ||
.then((res) => res.json()) | ||
.then((json) => { setDetails(json) }) | ||
.catch((error) => alert(error, 'error')) | ||
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. Good idea to add a catch in case of errors! :) |
||
.finally(() => console.log('movie-details')) | ||
}, [id]) | ||
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. Just out of curiosity, did you also get an error about not adding movie-details as a dependency? |
||
|
||
const goBack = () => { | ||
navigate(-1) | ||
} | ||
|
||
return ( | ||
<section className="details-page"> | ||
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. To display a background as well, you could add this code inside of the section tag for "details-page" |
||
<button type="button" className="back-link" onClick={goBack}> Back to movie list </button> | ||
<img className="solo-movie-poster" src={`https://image.tmdb.org/t/p/w342/${details.poster_path}`} alt="poster" /> | ||
<h2>{details.title}</h2> | ||
<p>{details.overview}</p> | ||
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. In order to not have the text spread out over the full width of the page, you could add |
||
|
||
</section> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,130 @@ body { | |
sans-serif; | ||
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. Daniel recommended splitting the CSS into separate files for each component. We found that it was easier for us to work asynchronously when having separate CSS files. |
||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
background-color: black; | ||
|
||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
monospace; | ||
|
||
} | ||
|
||
|
||
|
||
/*PopularList*/ | ||
.all-movies { | ||
display: flex; | ||
flex-direction: column; | ||
align-content: center; | ||
flex-wrap: wrap; | ||
width: 100%; | ||
box-sizing: border-box; | ||
|
||
} | ||
|
||
.movie-container { | ||
word-wrap: break-word; | ||
text-align: center; | ||
position: relative; | ||
} | ||
|
||
a.movie { | ||
display: flex; | ||
|
||
} | ||
|
||
.all-movies .movie-info { | ||
position: absolute; | ||
height: 100%; | ||
color: #f9f9f9; | ||
text-align: center; | ||
background: rgba(0,0,0,0.75); | ||
display: none; | ||
margin-top: auto; | ||
margin-bottom: 0; | ||
} | ||
|
||
.all-movies a:hover .movie-info { | ||
display: none; | ||
flex-wrap: wrap; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
max-width: 100%; | ||
} | ||
|
||
|
||
|
||
.all-movie-posters { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
/*ShowMovie*/ | ||
.back-link { | ||
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. If you want to style the button more, this is how we styled our button. We used flexbox to position it. :) .backButton { |
||
font-size: 10px; | ||
right: 75%; | ||
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 these properties do? Are they positioning the button? |
||
top: 35%; | ||
width: 30vh; | ||
} | ||
|
||
.details-page { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px; | ||
color: white; | ||
font-size: 16px; | ||
} | ||
|
||
|
||
.solo-movie-poster { | ||
width: 30vh; | ||
} | ||
|
||
|
||
@media (min-width: 670px) and (max-width: 1024px) { | ||
.all-movies { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: 2rem; | ||
justify-content: space-evenly; | ||
} | ||
} | ||
|
||
@media (min-width: 1024px) { | ||
.all-movies { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr 1fr; | ||
} | ||
|
||
.all-movies a:hover .movie-info { | ||
display: flex; | ||
flex-wrap: wrap; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
width: 100%; | ||
} | ||
|
||
.details-page { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px; | ||
color: white; | ||
font-size: 16px; | ||
text-align: center; | ||
} | ||
|
||
.solo-movie-poster { | ||
width: 30vh; | ||
align-self: center; | ||
} | ||
|
||
.back-link { | ||
font-size: 10px; | ||
right: 75%; | ||
top: 35%; | ||
width: 30vh; | ||
align-self: center | ||
} | ||
} | ||
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. We see that you used flexbox for the mobile version and grid for the other devices in the all-movies container. Interesting approach, we didn't think about it, wondering if the code might look cleaner when the same approach is used on all devices for one component? |
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.
The fetch is working perfectly, great job!