From 2d0bcaeeeffef4e6ed6f445378b9729e70901f61 Mon Sep 17 00:00:00 2001 From: real-zephex Date: Sat, 25 May 2024 16:58:02 +0530 Subject: =?UTF-8?q?=F0=9F=9A=80=20refactor(movie):=20revamped=20movie=20se?= =?UTF-8?q?ction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/movies/components/search.jsx | 71 ++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'src/app/movies/components/search.jsx') diff --git a/src/app/movies/components/search.jsx b/src/app/movies/components/search.jsx index dca163a..35b8432 100644 --- a/src/app/movies/components/search.jsx +++ b/src/app/movies/components/search.jsx @@ -1,38 +1,53 @@ "use client"; import { useState } from "react"; -import styles from "../styles/search.module.css"; -import { FaSearch } from "react-icons/fa"; -import SearchResults from "./search_2"; +import { Input, Progress } from "@nextui-org/react"; -export default function SEARCH_COMPONENT() { - const [title, setTitle] = useState(""); - const [result, setResults] = useState(null); +import { SearchMovie } from "./requestsHandler"; +import MovieSearchFormatter from "./searchFormatter"; - const fetch_results = async (title) => { - setResults(await SearchResults(title)); - }; +const MovieSearchBar = () => { + const [movieTitle, setMovieTitle] = useState(""); + const [loading, setLoading] = useState(<>); + const [movieResults, setMovieResults] = useState(<>); + + async function handleInputChange() { + setLoading( + + ); + const data = await SearchMovie(movieTitle); + setLoading(<>); + setMovieResults(await MovieSearchFormatter(data)); + } return ( -
-
- - setTitle(event.target.value)} - onKeyDown={async (e) => { - if ((e.key === "Enter" || e.code === 13) && title) { - await fetch_results(e.target.value); +
+
+ { + if (event.target.value.trim() !== "") { + setMovieTitle(event.target.value); } }} - > -
- -
{result}
-
+ onKeyDown={async (event) => { + if (event.key === "Enter" || event.code === "Enter") { + await handleInputChange(); + } + }} + /> + {loading} + +
{movieResults}
+ ); -} +}; + +export default MovieSearchBar; -- cgit v1.2.3