-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
75 lines (56 loc) · 1.74 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import './App.css';
import api from './api/axiosConfig';
import {useState, useEffect} from 'react';
import Layout from './components/Layout';
import {Routes, Route} from 'react-router-dom';
import Home from './components/home/Home';
import Header from './components/header/Header';
import Trailer from './components/trailer/Trailer';
import Reviews from './components/reviews/Reviews';
import NotFound from './components/notFound/NotFound';
function App() {
const [movies, setMovies] = useState();
const [movie, setMovie] = useState();
const [reviews, setReviews] = useState([]);
const getMovies = async () =>{
try
{
const response = await api.get("http://localhost:8080/api/v1/movies");
setMovies(response.data);
}
catch(err)
{
console.log(err);
}
}
const getMovieData = async (movieId) => {
try
{
const response = await api.get(`http:localhost:8080/api/v1/movies/${movieId}`);
const singleMovie = response.data;
setMovie(singleMovie);
setReviews(singleMovie.reviews);
}
catch (error)
{
console.error(error);
}
}
useEffect(() => {
getMovies();
},[])
return (
<div className="App">
<Header/>
<Routes>
<Route path="/" element={<Layout/>}>
<Route path="/" element={<Home movies={movies} />} ></Route>
<Route path="/Trailer/:ytTrailerId" element={<Trailer/>}></Route>
<Route path="/Reviews/:movieId" element ={<Reviews getMovieData = {getMovieData} movie={movie} reviews ={reviews} setReviews = {setReviews} />}></Route>
<Route path="*" element = {<NotFound/>}></Route>
</Route>
</Routes>
</div>
);
}
export default App;