blob: dc641e1e32f19ab8277fe7a9fafda7593c3989ed (
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
|
"use client";
import styles from "../styles/search.module.css";
import { useState } from "react";
import { FaSearch } from "react-icons/fa";
import FetchSearchTitle from "./searchQuery";
import Image from "next/image";
import Link from "next/link";
import { PreFetchAnimeInfo } from "./cacher";
export default function DramaSearch() {
const [title, setTitle] = useState("");
const [infoTitle, setInfoTitle] = useState(null);
const [loadingText, setLoadingText] = useState(null);
const handleSearch = async (title) => {
setLoadingText(true);
const data = await FetchSearchTitle(title);
PreFetchAnimeInfo(data);
setLoadingText(false);
setInfoTitle(data);
};
return (
<div className={styles.SearchContainer}>
<div className={styles.Search}>
<FaSearch color="white" size={16} />
<input
placeholder="Search for drama"
onChange={(event) => setTitle(event.target.value)}
onKeyDown={async (e) => {
if ((e.key === "Enter" || e.code === 13) && title) {
await handleSearch(e.target.value);
}
}}
></input>
</div>
{loadingText && (
<p className={styles.LoadingText}>Wait a moment...</p>
)}
<div className={styles.SearchResults}>
{infoTitle &&
infoTitle.results.map((item, index) => (
<Link
href={`/kdrama/${encodeURIComponent(item.id)}`}
style={{ textDecoration: "none" }}
key={index}
>
<div className={styles.SearchEntry}>
<p>{item.title}</p>
<Image
src={`https://sup-proxy.zephex0-f6c.workers.dev/api-content?url=${item.image}`}
width={120}
height={190}
alt="Drama Poster"
/>
</div>
</Link>
))}
</div>
</div>
);
}
|