diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-10 20:27:59 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-10 20:27:59 +0000 |
| commit | 364e82c7f2f10759b437c0282021d5dfef98c922 (patch) | |
| tree | 3760491f24b4c25d8d5c826fba9d796d48172550 /packages/web/app/dashboard/search | |
| parent | d6dd76021226802adf5295b3243d6f2ae4fa5cc2 (diff) | |
| download | karakeep-364e82c7f2f10759b437c0282021d5dfef98c922.tar.zst | |
feature: Change top nav to include search and move add link to a modal
Diffstat (limited to 'packages/web/app/dashboard/search')
| -rw-r--r-- | packages/web/app/dashboard/search/page.tsx | 68 |
1 files changed, 8 insertions, 60 deletions
diff --git a/packages/web/app/dashboard/search/page.tsx b/packages/web/app/dashboard/search/page.tsx index 514c546d..602f6aa0 100644 --- a/packages/web/app/dashboard/search/page.tsx +++ b/packages/web/app/dashboard/search/page.tsx @@ -1,76 +1,24 @@ "use client"; -import { api } from "@/lib/trpc"; -import { usePathname, useRouter, useSearchParams } from "next/navigation"; import BookmarksGrid from "@/components/dashboard/bookmarks/BookmarksGrid"; -import { Input } from "@/components/ui/input"; import Loading from "../bookmarks/loading"; -import { keepPreviousData } from "@tanstack/react-query"; -import { Search } from "lucide-react"; -import { ActionButton } from "@/components/ui/action-button"; import { Suspense, useRef } from "react"; +import { SearchInput } from "@/components/dashboard/search/SearchInput"; +import { useBookmarkSearch } from "@/lib/hooks/bookmark-search"; function SearchComp() { - const router = useRouter(); - const pathname = usePathname(); - const searchParams = useSearchParams(); - const searchQuery = searchParams.get("q") || ""; - - const { data, isPending, isPlaceholderData, error } = - api.bookmarks.searchBookmarks.useQuery( - { - text: searchQuery, - }, - { - placeholderData: keepPreviousData, - }, - ); - - if (error) { - throw error; - } + const { data, isPending, isPlaceholderData } = useBookmarkSearch(); const inputRef: React.MutableRefObject<HTMLInputElement | null> = useRef<HTMLInputElement | null>(null); - let timeoutId: NodeJS.Timeout | undefined; - - // Debounce user input - const doSearch = () => { - if (!inputRef.current) { - return; - } - router.replace(`${pathname}?q=${inputRef.current.value}`); - }; - - const onInputChange = () => { - if (timeoutId) { - clearTimeout(timeoutId); - } - timeoutId = setTimeout(() => { - doSearch(); - }, 200); - }; - return ( <div className="container flex flex-col gap-3 p-4"> - <div className="flex gap-2"> - <Input - ref={inputRef} - placeholder="Search" - defaultValue={searchQuery} - onChange={onInputChange} - /> - <ActionButton - loading={isPending || isPlaceholderData} - onClick={doSearch} - > - <span className="flex gap-2"> - <Search /> - <span className="my-auto">Search</span> - </span> - </ActionButton> - </div> + <SearchInput + ref={inputRef} + autoFocus={true} + loading={isPending || isPlaceholderData} + /> <hr /> {data ? ( <BookmarksGrid |
