clean up typing, remove duds from data
This commit is contained in:
parent
af983785bf
commit
2b79c825e8
21
src/App.tsx
21
src/App.tsx
|
@ -4,12 +4,21 @@ import { MovieWall } from './objects/movie-wall'
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import tmdb from './objects/tmdb'
|
import tmdb from './objects/tmdb'
|
||||||
import { Sidebar } from './objects/sidebar'
|
import { Sidebar } from './objects/sidebar'
|
||||||
|
import { makeImgUrl } from './functions'
|
||||||
|
import { Movie } from './objects/movie-wall'
|
||||||
|
|
||||||
export type Config = {
|
export type Config = {
|
||||||
language: string,
|
language: string,
|
||||||
region: string,
|
region: string,
|
||||||
page: number,
|
page: number,
|
||||||
}
|
}
|
||||||
|
class MovieClass implements Movie {
|
||||||
|
id = null
|
||||||
|
poster_path = null
|
||||||
|
backdrop_path = null
|
||||||
|
title = null
|
||||||
|
overview = null
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [config, setConfig] = useState<Config>({
|
const [config, setConfig] = useState<Config>({
|
||||||
|
@ -17,12 +26,14 @@ function App() {
|
||||||
region: "spain",
|
region: "spain",
|
||||||
page: 1
|
page: 1
|
||||||
})
|
})
|
||||||
const [movies, setMovies] = useState([])
|
const [movies, setMovies] = useState([new MovieClass()])
|
||||||
const [backdrop, setBackdrop] = useState("")
|
const [backdrop, setBackdrop] = useState("")
|
||||||
|
const [chosenMovie, setChosenMovie] = useState(new MovieClass())
|
||||||
|
|
||||||
useEffect(() => { tmdb.getPopular(config, setMovies) }, [])
|
useEffect(() => { tmdb.getPopular(config, setMovies) }, [])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (movies?.[0]) {
|
if (movies[0].backdrop_path) {
|
||||||
tmdb.getBackdrop(movies[0], setBackdrop)
|
setBackdrop(makeImgUrl(movies[0].backdrop_path))
|
||||||
}
|
}
|
||||||
}, [movies])
|
}, [movies])
|
||||||
return (
|
return (
|
||||||
|
@ -31,10 +42,10 @@ function App() {
|
||||||
<h1>Movie Explorer</h1>
|
<h1>Movie Explorer</h1>
|
||||||
</header>
|
</header>
|
||||||
<main style={{ backgroundImage: backdrop }}>
|
<main style={{ backgroundImage: backdrop }}>
|
||||||
<div className='flow-container'>
|
<div id="movie-wall-container">
|
||||||
<MovieWall movies={movies} setMovies={setMovies} config={config} />
|
<MovieWall movies={movies} setMovies={setMovies} config={config} />
|
||||||
</div>
|
</div>
|
||||||
<Sidebar movie={movies?.[0]} />
|
<Sidebar movie={chosenMovie} />
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -25,6 +25,7 @@ a:hover {
|
||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
min-width: 320px;
|
min-width: 320px;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
|
|
@ -3,13 +3,15 @@ import { Config } from "../App"
|
||||||
import tmdb from "./tmdb"
|
import tmdb from "./tmdb"
|
||||||
import { makeImgUrl } from "../functions"
|
import { makeImgUrl } from "../functions"
|
||||||
|
|
||||||
export type Movie = {
|
export interface Movie {
|
||||||
id: number
|
id: number | null
|
||||||
poster_path: string
|
poster_path: string | null
|
||||||
title: string
|
backdrop_path: string | null
|
||||||
overview: string
|
title: string | null
|
||||||
|
overview: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const sampleData = {
|
const sampleData = {
|
||||||
adult: false,
|
adult: false,
|
||||||
backdrop_path: "/jnE1GA7cGEfv5DJBoU2t4bZHaP4.jpg",
|
backdrop_path: "/jnE1GA7cGEfv5DJBoU2t4bZHaP4.jpg",
|
||||||
|
@ -57,10 +59,7 @@ interface PosterProps extends React.ComponentPropsWithRef<"div"> {
|
||||||
|
|
||||||
function Poster({ movie, config, listSimilar, setMovies }: PosterProps) {
|
function Poster({ movie, config, listSimilar, setMovies }: PosterProps) {
|
||||||
const style = {
|
const style = {
|
||||||
backgroundImage: makeImgUrl(movie.poster_path),
|
backgroundImage: makeImgUrl(movie.poster_path)
|
||||||
backgroundSize: "cover",
|
|
||||||
// alignSelf: "auto",
|
|
||||||
color: "inherit"
|
|
||||||
}
|
}
|
||||||
return <div className="poster" style={style}>
|
return <div className="poster" style={style}>
|
||||||
<div className="overlay" onClick={() => { listSimilar(config, movie, setMovies) }}>
|
<div className="overlay" onClick={() => { listSimilar(config, movie, setMovies) }}>
|
||||||
|
|
|
@ -5,8 +5,7 @@ export interface SidebarProps extends React.ComponentPropsWithRef<"div"> {
|
||||||
}
|
}
|
||||||
export function Sidebar({ movie }: SidebarProps) {
|
export function Sidebar({ movie }: SidebarProps) {
|
||||||
const style = {
|
const style = {
|
||||||
backgroundImage: "url(https://image.tmdb.org/t/p/w500/" + movie?.poster_path + ")",
|
|
||||||
backgroundSize: "cover",
|
|
||||||
}
|
}
|
||||||
return <div id="sidebar" style={style}>
|
return <div id="sidebar" style={style}>
|
||||||
<h1>{movie?.title ?? "loading"}</h1>
|
<h1>{movie?.title ?? "loading"}</h1>
|
||||||
|
|
|
@ -48,7 +48,10 @@ export default {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const array: Array<Movie> = res.data.results
|
const array: Array<Movie> = res.data.results
|
||||||
array.splice(18)
|
.filter((e: Movie) => {
|
||||||
|
return e.poster_path
|
||||||
|
})
|
||||||
|
array.splice(19)
|
||||||
array.unshift(movie)
|
array.unshift(movie)
|
||||||
callback(array)
|
callback(array)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue