2023-05-15 21:13:59 -05:00
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
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-23 18:07:26 -05:00
className = "inline-flex w-fit absolute right-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-23 18:07:26 -05:00
className = "border border-sky-100 rounded-md pr-10 w-44 sm:w-60 focus:border-sky-500 sm:focus:w-80 hover:border-sky-500 duration-100 outline-none p-2"
2023-05-15 21:13:59 -05:00
/ >
< / div >
2023-05-08 09:35:39 -05:00
) ;
}