Skip to content

Commit

Permalink
Configure react router dom and implemente new route
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlli committed Mar 21, 2022
1 parent ba4749a commit 1fdc857
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"styled-components": "^5.3.3",
"web-vitals": "^2.1.0"
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Routes, Route } from 'react-router-dom'

import Home from './pages/Home';
import Details from './pages/Details';

import './global.css'



ReactDOM.render(
<React.StrictMode>
<Home />
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/details/:id" element={<Details />} />
</Routes>
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root')
);
22 changes: 22 additions & 0 deletions src/pages/Details/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom'
// import { Container } from './styles';

function Details() {

const [movie, setMovie] = useState([]);
const { id } = useParams()

useEffect(() => {
fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=pt-BR&page=1`)
.then(respone => respone.json())
.then(data =>
setMovie(data))
}, [])

return (
<h1>{JSON.stringify(movie)}</h1>
);
}

export default Details;
5 changes: 5 additions & 0 deletions src/pages/Details/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styled from 'styled-components';

export const Container = styled.div`
`;
9 changes: 4 additions & 5 deletions src/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom'

import { Container, MovieList, Movie } from './styles';

function Home() {
useEffect(() => {
fetch(`https://api.themoviedb.org/3/movie/popular?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=en-US&page=1`)
fetch(`https://api.themoviedb.org/3/movie/popular?api_key=${process.env.REACT_APP_API_MOVIE_DB}&language=pt-BR&page=1`)
.then(respone => respone.json())
.then(data => setMovies(data.results))

}, [])

const [movies, setMovies] = useState([]);
const image_path = 'https://image.tmdb.org/t/p/w500/'
console.log(movies)

return (
<Container>
Expand All @@ -22,9 +21,9 @@ function Home() {
{movies.map(movie => {
return (
<Movie key={movie.id}>
<a href="/">
<Link to={`/details/${movie.id}`}>
<img src={`${image_path}${movie.poster_path}`} alt={movie.title} />
</a>
</Link>
<span>{movie.title}</span>
</Movie>
)
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@
core-js-pure "^3.20.2"
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.16.3", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
version "7.17.8"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.8.tgz#3e56e4aff81befa55ac3ac6a0967349fd1c5bca2"
integrity sha512-dQpEpK0O9o6lj6oPu0gRDbbnk+4LeHlNcBpspf6Olzt3GIX4P1lWF1gS+pHLDFlaJvbR6q7jCfQ08zA4QJBnmA==
Expand Down Expand Up @@ -4550,6 +4550,13 @@ he@^1.2.0:
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

history@^5.2.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/history/-/history-5.3.0.tgz#1548abaa245ba47992f063a0783db91ef201c73b"
integrity sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==
dependencies:
"@babel/runtime" "^7.7.6"

hoist-non-react-statics@^3.0.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
Expand Down Expand Up @@ -7113,6 +7120,21 @@ react-refresh@^0.11.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"
integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==

react-router-dom@^6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.2.2.tgz#f1a2c88365593c76b9612ae80154a13fcb72e442"
integrity sha512-AtYEsAST7bDD4dLSQHDnk/qxWLJdad5t1HFa1qJyUrCeGgEuCSw0VB/27ARbF9Fi/W5598ujvJOm3ujUCVzuYQ==
dependencies:
history "^5.2.0"
react-router "6.2.2"

react-router@6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.2.2.tgz#495e683a0c04461eeb3d705fe445d6cf42f0c249"
integrity sha512-/MbxyLzd7Q7amp4gDOGaYvXwhEojkJD5BtExkuKmj39VEE0m3l/zipf6h2WIB2jyAO0lI6NGETh4RDcktRm4AQ==
dependencies:
history "^5.2.0"

react-scripts@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.0.tgz#6547a6d7f8b64364ef95273767466cc577cb4b60"
Expand Down

0 comments on commit 1fdc857

Please sign in to comment.