From db6b29b7d21f374765f6279f2a1668afaada2488 Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Tue, 5 Sep 2023 17:31:22 +0200 Subject: [PATCH] :recycle: refactored movieform Co-authored-by: Sindre Kjelsrud --- src/App.tsx | 53 +++++-------------------- src/components/MovieForm/index.tsx | 64 ++++++++++++++++++++++++++++++ src/components/index.ts | 3 +- 3 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 src/components/MovieForm/index.tsx diff --git a/src/App.tsx b/src/App.tsx index f9bc564..899ab31 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,7 @@ import { useEffect, useState } from 'react' import './App.css' import q from 'qjuul' -import Pagination from './components/Pagination' -import { MovieTableRow } from './components' +import { MovieTableRow, MovieForm, Pagination } from './components' import type { movieObject } from './types/movie' import Modal from 'react-modal' @@ -95,48 +94,14 @@ function App() { 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 && ( void + setMovieTitle: (title: string) => void + setMovieYear: (year: string) => void + setMovieType: (type: string) => void +} + +const MovieForm: React.FC = ({ + handleMovieSubmit, + setMovieTitle, + setMovieType, + setMovieYear, +}) => { + return ( + + 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 + + + ) +} + +export default MovieForm diff --git a/src/components/index.ts b/src/components/index.ts index de0881d..2860fa7 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,2 +1,3 @@ -export { default as PaginationButton } from './PaginationButton' +export { default as Pagination } from './Pagination' export { default as MovieTableRow } from './MovieTableRow' +export { default as MovieForm } from './MovieForm'