Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion code/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Technigo React Starter App

You can find the project on: https://oscarreginaprojectmovies.netlify.app

This app has been generated using `create-react-app`, then cleaned up a little so we have a project with just the elements we need to get started.

Add components in the `src` folder and use them in `src/app.js` to get started.
Expand All @@ -16,4 +18,4 @@ Alternatively, if you don't want a new git repo on your account;
1. Download & extract the [latest release](https://github.com/Technigo/react-starter/releases/latest) from GitHub
1. Open the directory in the terminal: `cd /path/to/react-starter`
1. Install required dependencies with npm: `npm install`
1. Start the project: `npm start`
1. Start the project: `npm start`
63 changes: 62 additions & 1 deletion code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.9.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
28 changes: 24 additions & 4 deletions code/src/App.js
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>
);
}

27 changes: 27 additions & 0 deletions code/src/components/PopularList.js
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 }) => {

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!

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>
)
};
32 changes: 32 additions & 0 deletions code/src/components/ShowMovie.js
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'))

Choose a reason for hiding this comment

The 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])

Choose a reason for hiding this comment

The 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">
Copy link

Choose a reason for hiding this comment

The 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"
style={{ backgroundImage: url(https://image.tmdb.org/t/p/w1280${details.backdrop_path})` }}`

<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>

Choose a reason for hiding this comment

The 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 max-width to the p-element.


</section>
)
}

121 changes: 121 additions & 0 deletions code/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,130 @@ body {
sans-serif;

Choose a reason for hiding this comment

The 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 {

Choose a reason for hiding this comment

The 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 {
background-color: transparent;
color: white;
cursor: pointer;
font-weight: 700;
border: 5px white;
padding: 8px 15px;
opacity: 0.7;
display: flex;
flex-direction: row;
gap: 10px;
}

font-size: 10px;
right: 75%;

Choose a reason for hiding this comment

The 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
}
}

Choose a reason for hiding this comment

The 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?

1 change: 1 addition & 0 deletions code/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable linebreak-style */
import React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
Expand Down