2023-05-08 09:35:39 -05:00
|
|
|
import { faMagnifyingGlass } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2023-05-14 10:41:08 -05:00
|
|
|
import { useEffect, useState } from "react";
|
2023-05-08 09:35:39 -05:00
|
|
|
import useSearchSettingsStore from "@/store/search";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
export default function Search() {
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const [searchBox, setSearchBox] = useState(
|
|
|
|
false || router.pathname == "/search"
|
|
|
|
);
|
|
|
|
|
2023-05-15 21:13:59 -05:00
|
|
|
const { searchSettings, setSearchSettings, setSearchQuery } =
|
2023-05-08 09:35:39 -05:00
|
|
|
useSearchSettingsStore();
|
|
|
|
|
2023-05-14 10:41:08 -05:00
|
|
|
useEffect(() => {
|
2023-05-15 21:13:59 -05:00
|
|
|
if (router.pathname !== "/search")
|
|
|
|
setSearchSettings({
|
|
|
|
query: "",
|
|
|
|
filter: {
|
|
|
|
name: true,
|
|
|
|
url: true,
|
|
|
|
title: true,
|
|
|
|
collection: true,
|
|
|
|
tags: true,
|
|
|
|
},
|
|
|
|
});
|
2023-05-14 10:41:08 -05:00
|
|
|
}, [router]);
|
|
|
|
|
2023-05-08 09:35:39 -05:00
|
|
|
return (
|
2023-05-15 21:13:59 -05:00
|
|
|
<div
|
2023-05-23 18:07:26 -05:00
|
|
|
className="flex items-center relative group"
|
2023-05-15 21:13:59 -05:00
|
|
|
onClick={() => setSearchBox(true)}
|
|
|
|
>
|
|
|
|
<label
|
|
|
|
htmlFor="search-box"
|
2023-05-31 13:33:01 -05:00
|
|
|
className="inline-flex w-fit absolute left-2 pointer-events-none rounded-md p-1 text-sky-500 group-hover:text-sky-600"
|
2023-05-08 09:35:39 -05:00
|
|
|
>
|
2023-05-15 21:13:59 -05:00
|
|
|
<FontAwesomeIcon icon={faMagnifyingGlass} className="w-5 h-5" />
|
|
|
|
</label>
|
2023-05-08 09:35:39 -05:00
|
|
|
|
2023-05-15 21:13:59 -05:00
|
|
|
<input
|
|
|
|
id="search-box"
|
|
|
|
type="text"
|
|
|
|
placeholder="Search for Links"
|
|
|
|
value={searchSettings.query}
|
|
|
|
onChange={(e) => {
|
|
|
|
setSearchQuery(e.target.value);
|
|
|
|
router.push("/search");
|
|
|
|
}}
|
|
|
|
autoFocus={searchBox}
|
2023-05-31 13:33:01 -05:00
|
|
|
className="border border-sky-100 rounded-md pl-10 py-2 pr-2 w-44 sm:w-60 focus:border-sky-500 sm:focus:w-80 hover:border-sky-500 duration-100 outline-none"
|
2023-05-15 21:13:59 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-05-08 09:35:39 -05:00
|
|
|
);
|
|
|
|
}
|