From 50a0f0240d7fef133eb5acc1bea2b1168b08e9db Mon Sep 17 00:00:00 2001 From: Factiven Date: Sun, 24 Dec 2023 13:03:54 +0700 Subject: migrate to typescript --- components/searchPalette.js | 282 -------------------------------------------- 1 file changed, 282 deletions(-) delete mode 100644 components/searchPalette.js (limited to 'components/searchPalette.js') diff --git a/components/searchPalette.js b/components/searchPalette.js deleted file mode 100644 index b450423..0000000 --- a/components/searchPalette.js +++ /dev/null @@ -1,282 +0,0 @@ -import { Fragment, useEffect, useRef, useState } from "react"; -import { Combobox, Dialog, Menu, Transition } from "@headlessui/react"; -import useDebounce from "../lib/hooks/useDebounce"; -import Image from "next/image"; -import { useRouter } from "next/router"; -import { useSearch } from "../lib/context/isOpenState"; -import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; -import { BookOpenIcon, PlayIcon } from "@heroicons/react/20/solid"; -import { useAniList } from "../lib/anilist/useAnilist"; -import { getFormat } from "../utils/getFormat"; -import SearchByImage from "./search/searchByImage"; - -export default function SearchPalette() { - const { isOpen, setIsOpen } = useSearch(); - const { quickSearch } = useAniList(); - - const [query, setQuery] = useState(""); - const [data, setData] = useState(null); - const debounceSearch = useDebounce(query, 500); - const [loading, setLoading] = useState(false); - const [type, setType] = useState("ANIME"); - - const [nextPage, setNextPage] = useState(false); - - let focusInput = useRef(null); - const router = useRouter(); - - function closeModal() { - setIsOpen(false); - } - - function handleChange(event) { - router.push(`/en/${type.toLowerCase()}/${event}`); - } - - async function advance() { - setLoading(true); - const res = await quickSearch({ - search: debounceSearch, - type, - }); - setData(res?.data?.Page?.results); - setNextPage(res?.data?.Page?.pageInfo?.hasNextPage); - setLoading(false); - } - - useEffect(() => { - advance(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [debounceSearch, type]); - - useEffect(() => { - const handleKeyDown = (e) => { - if (e.code === "KeyS" && e.ctrlKey) { - // do your stuff - e.preventDefault(); - setIsOpen((prev) => !prev); - setData(null); - setQuery(""); - } - }; - - window.addEventListener("keydown", handleKeyDown); - - return () => { - window.removeEventListener("keydown", handleKeyDown); - }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - return ( - - - -
- - -
-
- - - { - handleChange(e); - setData(null); - setIsOpen(false); - setQuery(""); - }} - > -
-
-

For quick access :

-
- CTRL -
- + -
- S -
-
-
- -
- - {type.toLowerCase()} - -
- - -
- - {({ active }) => ( - - )} - - - {({ active }) => ( - - )} - -
-
-
-
- -
-
-
- setQuery(event.target.value)} - /> -
- - {!loading ? ( - - {data?.length > 0 - ? data?.map((i) => ( - - `flex items-center gap-3 p-5 ${ - active ? "bg-primary/40 cursor-pointer" : "" - }` - } - > -
- coverImage -
-
-

- {i.title.userPreferred} -

-

- {i.startDate.year} {getFormat(i.format)} -

-
-
- )) - : !loading && - debounceSearch !== "" && ( -

- No results found. -

- )} - {nextPage && ( - - )} -
- ) : ( -
-
-
- - - - -
-
-
- )} -
-
-
-
-
-
-
-
- ); -} -- cgit v1.2.3