|
1 | 1 | "use client" |
2 | | -import {SearchBar} from "@/components/SearchBar"; |
3 | | -import {LemonLogo} from "@/components/icons/LemonLogo"; |
4 | | -import React, {useEffect, useState} from "react"; |
5 | | -import {useThrottle} from "@/hooks/useThrottle"; |
| 2 | +import { SearchBar } from "@/components/SearchBar"; |
| 3 | +import { LemonLogo } from "@/components/icons/LemonLogo"; |
| 4 | +import React, { useEffect, useState } from "react"; |
| 5 | +import { useThrottle } from "@/hooks/useThrottle"; |
6 | 6 | import Image from "next/image"; |
7 | | -import {SearchResult, StatusResult} from "@/types"; |
| 7 | +import { SearchResult, } from "@/types"; |
8 | 8 | import Link from "next/link"; |
9 | 9 |
|
10 | 10 | export default function Home() { |
11 | 11 | const [searchText, setSearchText] = useState("") |
12 | 12 | const throttledInputText = useThrottle(searchText, 1000) |
13 | 13 | const [searchResult, setSearchResult] = useState<SearchResult>({ |
14 | | - hits : [], query : "", processingTimeMs : 0, limit : 0, offset : 0, estimatedTotalHits :0 |
| 14 | + data: [], total_page: 1, total_elements: 0 |
15 | 15 | }) |
16 | | - const [totalCount, setTotalCount] = useState(0) |
17 | 16 |
|
18 | 17 | useEffect(() => { |
19 | | - async function handleSearchTextChange(){ |
20 | | - const response = await fetch("https://meili.rabbitprotocol.com/indexes/arca-con/search", { |
21 | | - method : "POST", |
| 18 | + async function handleSearchTextChange() { |
| 19 | + const response = await fetch("https://search.lemondouble.com/arca_con/search", { |
| 20 | + method: "POST", |
22 | 21 | headers: { |
23 | | - 'Content-Type' : 'application/json', |
24 | | - 'Authorization' : 'Bearer 6650f03192cafd48c3cce16810b0cf588690e501eb883ac0b5ae6b8df03d68ef' |
| 22 | + 'Content-Type': 'application/json', |
25 | 23 | }, |
26 | | - body : JSON.stringify({ |
27 | | - "q": throttledInputText, |
28 | | - "attributesToSearchOn" : ["text"], |
29 | | - "attributesToHighlight" :["text"], |
30 | | - "highlightPreTag": "<search-highlight>", |
31 | | - "highlightPostTag": "</search-highlight>", |
32 | | - "limit": 101, |
33 | | - "offset": 0 |
| 24 | + body: JSON.stringify({ |
| 25 | + "query": throttledInputText, |
| 26 | + "page": 1, |
| 27 | + "size": 40 |
34 | 28 | }) |
35 | 29 | }) |
36 | | - const result : SearchResult = await response.json() |
| 30 | + const result: SearchResult = await response.json() |
37 | 31 | setSearchResult(result) |
38 | 32 | } |
39 | 33 |
|
40 | | - async function handleTotalCount(){ |
41 | | - const response = await fetch("https://meili.rabbitprotocol.com/indexes/arca-con/stats", { |
42 | | - method : "GET", |
43 | | - headers: { |
44 | | - 'Content-Type' : 'application/json', |
45 | | - 'Authorization' : 'Bearer 6650f03192cafd48c3cce16810b0cf588690e501eb883ac0b5ae6b8df03d68ef' |
46 | | - } |
47 | | - }) |
48 | | - |
49 | | - const result : StatusResult = await response.json() |
50 | | - setTotalCount(result.numberOfDocuments) |
51 | | - } |
52 | | - |
53 | 34 | handleSearchTextChange() |
54 | | - handleTotalCount() |
55 | 35 |
|
56 | 36 | }, [throttledInputText]); |
57 | 37 |
|
58 | | - return ( |
59 | | - <main className="w-screen h-auto min-h-screen overflow-hidden"> |
60 | | - <header className="w-screen h-[80px] bg-lemon-yellow px-4 flex flex-row space-x-3 items-center"> |
61 | | - <LemonLogo width={32} height={32} /> |
62 | | - <span className="text-2xl font-extrabold">LemonDouble</span> |
63 | | - </header> |
64 | | - <div id="container" className="h-full xl:mx-[360px] flex flex-col items-center"> |
65 | | - <span className="text-3xl xl:text-6xl font-extrabold text-black-1 mt-12 text-nowrap">아카콘 미러</span> |
66 | | - <span className="text-xl xl:text-3xl font-extrabold text-black-3 mt-3 text-nowrap">그런데 이제 대사로도 검색이 되는</span> |
67 | | - <br /> |
68 | | - <span className="text-base text-black-1"> 현재 검색가능한 콘 개수 : {totalCount}개</span> |
69 | | - <SearchBar |
70 | | - value={searchText} |
71 | | - onChange={(e) => setSearchText(e.target.value)} |
72 | | - /> |
73 | | - <div id="stack" className="mt-2 flex flex-col space-y-2 mx-2"> |
74 | | - {searchResult.hits.map(item => ( |
75 | | - <div className="xl:w-[790px] p-2 xl:p-8 flex flex-row space-x-5 bg-white-1 border-2 border-b-black-1 rounded-2xl" key={item.url}> |
76 | | - <Image src={item.url} alt={"아카콘 이미지"} width={100} height={100} /> |
77 | | - <div className="flex flex-col grow"> |
78 | | - <span className="text-2xl font-bold text-black-1">{item.con_title}</span> |
79 | | - <Link href={`https://arca.live/e/${item.con_number}`} target="_blank"> |
80 | | - <span className="text-lg font-normal text-black-3">{`https://arca.live/e/${item.con_number}`}</span> |
81 | | - </Link> |
82 | | - <span className="mt-2 text-lg font-semibold text-black-1" dangerouslySetInnerHTML={{__html : item._formatted.text}}></span> |
| 38 | + return ( |
| 39 | + <main className="w-screen h-auto min-h-screen overflow-hidden"> |
| 40 | + <header className="w-screen h-[80px] bg-lemon-yellow px-4 flex flex-row space-x-3 items-center"> |
| 41 | + <LemonLogo width={32} height={32} /> |
| 42 | + <span className="text-2xl font-extrabold">LemonDouble</span> |
| 43 | + </header> |
| 44 | + <div id="container" className="h-full xl:mx-[360px] flex flex-col items-center"> |
| 45 | + <span className="text-3xl xl:text-6xl font-extrabold text-black-1 mt-12 text-nowrap">아카콘 미러</span> |
| 46 | + <span className="text-xl xl:text-3xl font-extrabold text-black-3 mt-3 text-nowrap">그런데 이제 대사로도 검색이 되는</span> |
| 47 | + <br /> |
| 48 | + {searchResult.total_elements != 0 && <span className="text-base text-black-1"> 총 검색된 콘 개수 : {searchResult.total_elements}개</span>} |
| 49 | + <SearchBar |
| 50 | + value={searchText} |
| 51 | + onChange={(e) => setSearchText(e.target.value)} |
| 52 | + /> |
| 53 | + <div id="stack" className="mt-2 flex flex-col space-y-2 mx-2"> |
| 54 | + {searchResult.data.map(item => ( |
| 55 | + <div className="xl:w-[790px] p-2 xl:p-8 flex flex-row space-x-5 bg-white-1 border-2 border-b-black-1 rounded-2xl" key={item.url}> |
| 56 | + <Image src={item.url} alt={"아카콘 이미지"} width={100} height={100} /> |
| 57 | + <div className="flex flex-col grow"> |
| 58 | + <span className="text-2xl font-bold text-black-1">{item.con_title}</span> |
| 59 | + <Link href={`https://arca.live/e/${item.con_number}`} target="_blank"> |
| 60 | + <span className="text-lg font-normal text-black-3">{`https://arca.live/e/${item.con_number}`}</span> |
| 61 | + </Link> |
| 62 | + <span className="mt-2 text-lg font-semibold text-black-1" dangerouslySetInnerHTML={{ __html: item.text }}></span> |
| 63 | + </div> |
83 | 64 | </div> |
84 | | - </div> |
85 | | - ))} |
| 65 | + ))} |
| 66 | + |
| 67 | + </div> |
86 | 68 | </div> |
87 | | - </div> |
88 | | - </main> |
89 | | - ) |
| 69 | + </main> |
| 70 | + ) |
90 | 71 | } |
0 commit comments