aboutsummaryrefslogtreecommitdiff
path: root/src/app/movies/components/search.jsx
blob: 6514b76680059b41472e4438e26fa9bd3404cc19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use client";

import { useState } from "react";
import styles from "../styles/search.module.css";
import { FaSearch } from "react-icons/fa";
import SearchResults from "./search_2";

export default function SEARCH_COMPONENT() {
	const [title, setTitle] = useState("");
	const [result, setResults] = useState(null);

	const fetch_results = async (title) => {
		setResults(await SearchResults(title));
	};

	return (
		<main className={styles.Main}>
			<section className={styles.InputContainer}>
				<FaSearch
					color="white"
					className={styles.SearchIcon}
					size={17}
				/>
				<input
					placeholder="Enter movie title here"
					onChange={(event) => setTitle(event.target.value)}
					onKeyDown={async (e) => {
						if ((e.key === "Enter" || e.code === 13) && title) {
							await fetch_results(e.target.value);
						}
					}}
				></input>
			</section>

			<section className={styles.SearchResults}>{result}</section>
		</main>
	);
}