81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import React, { useState } from "react"
|
|
import { Config } from "../App"
|
|
import tmdb from "./tmdb"
|
|
|
|
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",
|
|
genre_ids: [28, 878],
|
|
id: 1094844,
|
|
original_language: "en",
|
|
original_title: "Ape vs. Mecha Ape",
|
|
overview: "Recognizing the destructive power of its captive giant Ape, the military makes its own battle-ready A.I., Mecha Ape. But its first practical test goes horribly wrong, leaving the military no choice but to release the imprisoned giant ape to stop the colossal robot before it destroys downtown Chicago.",
|
|
popularity: 2157.099,
|
|
poster_path: "/dJaIw8OgACelojyV6YuVsOhtTLO.jpg",
|
|
release_date: "2023-03-24",
|
|
title: "Ape vs. Mecha Ape",
|
|
video: false,
|
|
vote_average: 5.538,
|
|
vote_count: 52
|
|
}
|
|
|
|
interface MovieWallProps extends React.ComponentPropsWithRef<"div"> {
|
|
movies: Array<Movie>;
|
|
setMovies: Function;
|
|
setChosenMovie: Function;
|
|
setLoadedMovies: Function;
|
|
config: Config;
|
|
}
|
|
|
|
export function MovieWall({ movies, setMovies, config, setChosenMovie, setLoadedMovies }: MovieWallProps) {
|
|
|
|
const posters: Array<React.Component> = []
|
|
for (let i = 0; i < movies.length; i++) {
|
|
posters.push(
|
|
<Poster movie={movies[i]} key={movies[i].id} index={i} listSimilar={tmdb.getSimilar} config={config} setMovies={setMovies} setChosenMovie={setChosenMovie} setLoadedMovies={setLoadedMovies} />
|
|
)
|
|
}
|
|
return <>
|
|
{posters}
|
|
</>
|
|
}
|
|
|
|
interface PosterProps extends React.ComponentPropsWithRef<"div"> {
|
|
movie: Movie;
|
|
listSimilar: Function;
|
|
index: number;
|
|
config: Config;
|
|
setMovies: Function;
|
|
setChosenMovie: Function;
|
|
setLoadedMovies: Function;
|
|
}
|
|
|
|
|
|
function Poster({ movie, config, listSimilar, setMovies, setChosenMovie, setLoadedMovies }: PosterProps) {
|
|
function clickHandler() {
|
|
setChosenMovie(movie)
|
|
listSimilar(config, movie, setMovies)
|
|
}
|
|
const style = {
|
|
// backgroundImage: img.src
|
|
}
|
|
return <div className="poster" style={style}>
|
|
<div className="overlay" onClick={() => clickHandler()}>
|
|
</div>
|
|
<img
|
|
src={tmdb.makeImgUrl(movie.poster_path ?? "")}
|
|
onLoad={() => console.log("LOADED IMG")}
|
|
/>
|
|
</div>
|
|
}
|
|
|