🚧 working on form
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
		
							parent
							
								
									bf107bd256
								
							
						
					
					
						commit
						ffe520b94d
					
				
					 1 changed files with 86 additions and 28 deletions
				
			
		
							
								
								
									
										72
									
								
								src/App.tsx
									
										
									
									
									
								
							
							
						
						
									
										72
									
								
								src/App.tsx
									
										
									
									
									
								
							|  | @ -14,6 +14,9 @@ function App() { | ||||||
|   const [totalPages, setTotalPages] = useState(0) |   const [totalPages, setTotalPages] = useState(0) | ||||||
|   const [modalOpen, setModalOpen] = useState(false) |   const [modalOpen, setModalOpen] = useState(false) | ||||||
|   const [modalMovie, setModalMovie] = useState<movieObject | null>(null) |   const [modalMovie, setModalMovie] = useState<movieObject | null>(null) | ||||||
|  |   const [movieType, setMovieType] = useState('') | ||||||
|  |   const [movieYear, setMovieYear] = useState('') | ||||||
|  |   const [movieTitle, setMovieTitle] = useState('') | ||||||
| 
 | 
 | ||||||
|   console.log('App mounted') |   console.log('App mounted') | ||||||
| 
 | 
 | ||||||
|  | @ -29,7 +32,7 @@ function App() { | ||||||
|       }) |       }) | ||||||
|       .then(() => setLoading(false)) |       .then(() => setLoading(false)) | ||||||
|       .catch((error) => console.log(error)) |       .catch((error) => console.log(error)) | ||||||
|   }, []) |   }, [currentPage]) | ||||||
| 
 | 
 | ||||||
|   const calculatePages = (totalResults: number): number => { |   const calculatePages = (totalResults: number): number => { | ||||||
|     return Math.round(totalResults / 10) |     return Math.round(totalResults / 10) | ||||||
|  | @ -44,9 +47,24 @@ function App() { | ||||||
|     setModalMovie(movie) |     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 ( |   return ( | ||||||
|     <> |     <> | ||||||
|       <q.div className="flex flex-col justify-center items-center mx-auto w-3/4"> |       <q.div className="flex flex-col justify-center items-center mx-auto w-2/4"> | ||||||
|         <Modal |         <Modal | ||||||
|           className="p-6 bg-black rounded-lg outline-none" // styles for the modal container
 |           className="p-6 bg-black rounded-lg outline-none" // styles for the modal container
 | ||||||
|           overlayClassName="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center" // styles for the overlay
 |           overlayClassName="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center" // styles for the overlay
 | ||||||
|  | @ -75,8 +93,48 @@ function App() { | ||||||
|           </q.div> |           </q.div> | ||||||
|         </Modal> |         </Modal> | ||||||
|         <q.div className="flex flex-col w-full items-center"> |         <q.div className="flex flex-col w-full items-center"> | ||||||
|           <q.h1>All movies</q.h1> |           <q.h1 className="py-4">All movies</q.h1> | ||||||
|           <q.div className="flex pt-2"> | 
 | ||||||
|  |           <q.form className="flex flex-col gap-3 card p-4 rounded-lg w-full px-28"> | ||||||
|  |             <q.label>Choose a movie title:</q.label> | ||||||
|  |             <q.input | ||||||
|  |               type="text" | ||||||
|  |               id="movieTitle" | ||||||
|  |               placeholder="Movie title" | ||||||
|  |               onChange={(e) => 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" | ||||||
|  |             /> | ||||||
|  |             <q.label>Choose year movie was made: (OPTIONAL)</q.label> | ||||||
|  |             <q.select | ||||||
|  |               className="p-2 rounded-md border  border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent" | ||||||
|  |               onChange={(e) => setMovieYear(e.target.value)} | ||||||
|  |             > | ||||||
|  |               {/* Option for year 1923-2023 */} | ||||||
|  |               <q.option value="">All years</q.option> | ||||||
|  |               {Array.from(Array(100), (e, i) => { | ||||||
|  |                 const year = 2023 - i | ||||||
|  |                 return ( | ||||||
|  |                   <q.option key={i} value={year}> | ||||||
|  |                     {year} | ||||||
|  |                   </q.option> | ||||||
|  |                 ) | ||||||
|  |               })} | ||||||
|  |             </q.select> | ||||||
|  |             <q.label>Choose type: (OPTIONAL)</q.label> | ||||||
|  |             <q.select | ||||||
|  |               className="p-2 rounded-md border  border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent" | ||||||
|  |               onChange={(e) => setMovieType(e.target.value)} | ||||||
|  |             > | ||||||
|  |               <q.option value="">All types</q.option> | ||||||
|  |               <q.option value="movie">Movies</q.option> | ||||||
|  |               <q.option value="series">Series</q.option> | ||||||
|  |               <q.option value="episode">Episodes</q.option> | ||||||
|  |             </q.select> | ||||||
|  |             <q.button className="bg-white p-3 my-2 rounded-md w-2/5 mx-auto text-red-900 font-semibold"> | ||||||
|  |               Find movies | ||||||
|  |             </q.button> | ||||||
|  |           </q.form> | ||||||
|  |           <q.div className="flex pt-10"> | ||||||
|             {!loading && totalPages && ( |             {!loading && totalPages && ( | ||||||
|               <Pagination |               <Pagination | ||||||
|                 currentPage={currentPage} |                 currentPage={currentPage} | ||||||
|  | @ -85,10 +143,9 @@ function App() { | ||||||
|               /> |               /> | ||||||
|             )} |             )} | ||||||
|           </q.div> |           </q.div> | ||||||
|         </q.div> |  | ||||||
|           {!loading && movies ? ( |           {!loading && movies ? ( | ||||||
|           <q.div> |             <q.div className="w-full"> | ||||||
|             <q.table className="border-separate border-spacing-y-5"> |               <q.table className="border-separate border-spacing-y-5 w-full"> | ||||||
|                 <q.thead> |                 <q.thead> | ||||||
|                   <q.tr> |                   <q.tr> | ||||||
|                     <q.th>Poster</q.th> |                     <q.th>Poster</q.th> | ||||||
|  | @ -111,6 +168,7 @@ function App() { | ||||||
|             <q.h1>Loading...</q.h1> |             <q.h1>Loading...</q.h1> | ||||||
|           )} |           )} | ||||||
|         </q.div> |         </q.div> | ||||||
|  |       </q.div> | ||||||
|     </> |     </> | ||||||
|   ) |   ) | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 haraldnilsen
						haraldnilsen