blob: f543fd863d2b5f7b25bd828f50ea51330c0a5283 (
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
"use client";
import styles from "./search.module.css";
import { FaSearch } from "react-icons/fa"; // Import the search icon from react-icons library
import { useState } from "react";
import Results from "./components/fetchInfo";
import fetchedInfo from "./components/fetchedInfo";
import Link from "next/link";
export default function Input() {
const [searchedAnime, setSearchedAnime] = useState(null);
const [loading, setLoading] = useState(null);
const [info, setInfo] = useState(null);
const handleKeyPress = async (event) => {
if (
(event.code === "Enter" ||
event.key === "Enter" ||
event.code === 13) &&
searchedAnime !== ""
) {
setLoading(true);
setInfo(await fetchedInfo(await Results(searchedAnime)));
setLoading(false);
} else if (
(event.code === "Enter" ||
event.key === "Enter" ||
event.code === 13) &&
searchedAnime === ""
) {
alert("Input cannot be empty");
}
};
return (
<div style={{ marginBottom: -15 }}>
<div className={styles.inputContainer}>
<div className={styles.searchContainer}>
<FaSearch className={styles.searchIcon} />
<input
onChange={(event) => {
if (event.target.value.trim() !== "") {
setSearchedAnime(event.target.value);
}
}}
onKeyDown={(event) => handleKeyPress(event)}
placeholder="Enter anime title"
className={styles.SearchInput}
></input>
</div>
<div>
<button>
<Link href={"/anime/history/continueWatching"}>
History
</Link>
</button>
</div>
</div>
{loading && (
<p className={styles.waitWhileLoading}>
Please wait while we crunch all the data for you
</p>
)}
{info}
</div>
);
}
|