movie-explorer/src/App.tsx

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-05-05 21:59:33 +00:00
import './defaults.css'
2024-04-29 11:19:01 +00:00
import './App.css'
2024-05-02 20:47:28 +00:00
import { MovieWall } from './objects/movie-wall'
import { useState, useEffect } from 'react'
import tmdb from './objects/tmdb'
2024-05-06 11:33:00 +00:00
import { Sidebar } from './objects/sidebar'
2024-05-07 11:09:48 +00:00
import { makeImgUrl } from './functions'
import { Movie } from './objects/movie-wall'
2024-04-29 11:19:01 +00:00
2024-05-02 20:47:28 +00:00
export type Config = {
language: string,
2024-05-06 09:09:21 +00:00
region: string,
page: number,
2024-05-02 20:47:28 +00:00
}
2024-05-07 11:09:48 +00:00
class MovieClass implements Movie {
id = null
poster_path = null
backdrop_path = null
title = null
overview = null
}
2024-04-29 11:19:01 +00:00
2024-05-02 20:47:28 +00:00
function App() {
const [config, setConfig] = useState<Config>({
language: "es",
2024-05-05 21:59:33 +00:00
region: "spain",
page: 1
2024-05-02 20:47:28 +00:00
})
2024-05-07 11:09:48 +00:00
const [movies, setMovies] = useState([new MovieClass()])
2024-05-06 11:33:00 +00:00
const [backdrop, setBackdrop] = useState("")
2024-05-07 11:09:48 +00:00
const [chosenMovie, setChosenMovie] = useState(new MovieClass())
2024-05-05 21:59:33 +00:00
useEffect(() => { tmdb.getPopular(config, setMovies) }, [])
2024-05-06 11:33:00 +00:00
useEffect(() => {
2024-05-07 11:09:48 +00:00
if (movies[0].backdrop_path) {
setBackdrop(makeImgUrl(movies[0].backdrop_path))
2024-05-06 11:33:00 +00:00
}
}, [movies])
2024-04-29 11:19:01 +00:00
return (
<>
<header>
<h1>Movie Explorer</h1>
</header>
2024-05-06 11:33:00 +00:00
<main style={{ backgroundImage: backdrop }}>
2024-05-07 11:09:48 +00:00
<div id="movie-wall-container">
2024-05-06 09:09:21 +00:00
<MovieWall movies={movies} setMovies={setMovies} config={config} />
2024-05-05 21:59:33 +00:00
</div>
2024-05-07 11:09:48 +00:00
<Sidebar movie={chosenMovie} />
2024-04-29 11:19:01 +00:00
</main>
2024-05-02 20:47:28 +00:00
2024-04-29 11:19:01 +00:00
</>
)
}
export default App