diff --git a/src/App.tsx b/src/App.tsx index fb9f3c5..62c770a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,9 @@ function App() { const [totalPages, setTotalPages] = useState(0) const [modalOpen, setModalOpen] = useState(false) const [modalMovie, setModalMovie] = useState(null) + const [movieType, setMovieType] = useState('') + const [movieYear, setMovieYear] = useState('') + const [movieTitle, setMovieTitle] = useState('') console.log('App mounted') @@ -29,7 +32,7 @@ function App() { }) .then(() => setLoading(false)) .catch((error) => console.log(error)) - }, []) + }, [currentPage]) const calculatePages = (totalResults: number): number => { return Math.round(totalResults / 10) @@ -44,9 +47,24 @@ function App() { setModalMovie(movie) } + const handleMovieSubmit = (event: any) => { + event.preventDefault() + fetch( + `http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=${movieTitle}&type=${movieType}&y=${movieYear}` + ) + .then((response) => response.json()) + .then((data) => { + setMovies(data.Search) + console.log(data) + setTotalPages(data.totalResults) + }) + .then(() => setLoading(false)) + .catch((error) => console.log(error)) + } + return ( <> - + - All movies - + All movies + + + Choose a movie title: + setMovieTitle(e.target.value)} + className="border border-gray-300 rounded-md p-2 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent" + /> + Choose year movie was made: (OPTIONAL) + setMovieYear(e.target.value)} + > + {/* Option for year 1923-2023 */} + All years + {Array.from(Array(100), (e, i) => { + const year = 2023 - i + return ( + + {year} + + ) + })} + + Choose type: (OPTIONAL) + setMovieType(e.target.value)} + > + All types + Movies + Series + Episodes + + + Find movies + + + {!loading && totalPages && ( )} + {!loading && movies ? ( + + + + + Poster + Title + Year + + + + {movies.map((movie: any) => ( + handleModalOpen(movie)} + /> + ))} + + + + ) : ( + Loading... + )} - {!loading && movies ? ( - - - - - Poster - Title - Year - - - - {movies.map((movie: any) => ( - handleModalOpen(movie)} - /> - ))} - - - - ) : ( - Loading... - )} )