diff --git a/src/App.tsx b/src/App.tsx index 6dc13e1..2525a62 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,12 +4,21 @@ import { MovieWall } from './objects/movie-wall' import { useState, useEffect } from 'react' import tmdb from './objects/tmdb' import { Sidebar } from './objects/sidebar' +import { makeImgUrl } from './functions' +import { Movie } from './objects/movie-wall' export type Config = { language: string, region: string, page: number, } +class MovieClass implements Movie { + id = null + poster_path = null + backdrop_path = null + title = null + overview = null +} function App() { const [config, setConfig] = useState({ @@ -17,12 +26,14 @@ function App() { region: "spain", page: 1 }) - const [movies, setMovies] = useState([]) + const [movies, setMovies] = useState([new MovieClass()]) const [backdrop, setBackdrop] = useState("") + const [chosenMovie, setChosenMovie] = useState(new MovieClass()) + useEffect(() => { tmdb.getPopular(config, setMovies) }, []) useEffect(() => { - if (movies?.[0]) { - tmdb.getBackdrop(movies[0], setBackdrop) + if (movies[0].backdrop_path) { + setBackdrop(makeImgUrl(movies[0].backdrop_path)) } }, [movies]) return ( @@ -31,10 +42,10 @@ function App() {

Movie Explorer

-
+
- +
diff --git a/src/index.css b/src/index.css index 2bd6a6b..18aa9a2 100644 --- a/src/index.css +++ b/src/index.css @@ -25,6 +25,7 @@ a:hover { body { margin: 0; + display: flex; place-items: center; min-width: 320px; min-height: 100vh; diff --git a/src/objects/movie-wall.tsx b/src/objects/movie-wall.tsx index 0d17662..292d9a5 100644 --- a/src/objects/movie-wall.tsx +++ b/src/objects/movie-wall.tsx @@ -3,13 +3,15 @@ import { Config } from "../App" import tmdb from "./tmdb" import { makeImgUrl } from "../functions" -export type Movie = { - id: number - poster_path: string - title: string - overview: string +export interface Movie { + id: number | null + poster_path: string | null + backdrop_path: string | null + title: string | null + overview: string | null } + const sampleData = { adult: false, backdrop_path: "/jnE1GA7cGEfv5DJBoU2t4bZHaP4.jpg", @@ -57,10 +59,7 @@ interface PosterProps extends React.ComponentPropsWithRef<"div"> { function Poster({ movie, config, listSimilar, setMovies }: PosterProps) { const style = { - backgroundImage: makeImgUrl(movie.poster_path), - backgroundSize: "cover", - // alignSelf: "auto", - color: "inherit" + backgroundImage: makeImgUrl(movie.poster_path) } return
{ listSimilar(config, movie, setMovies) }}> diff --git a/src/objects/sidebar.tsx b/src/objects/sidebar.tsx index bd25608..3e6281b 100644 --- a/src/objects/sidebar.tsx +++ b/src/objects/sidebar.tsx @@ -5,8 +5,7 @@ export interface SidebarProps extends React.ComponentPropsWithRef<"div"> { } export function Sidebar({ movie }: SidebarProps) { const style = { - backgroundImage: "url(https://image.tmdb.org/t/p/w500/" + movie?.poster_path + ")", - backgroundSize: "cover", + } return