aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/lib
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2025-08-24 01:33:20 +0300
committerMohamedBassem <me@mbassem.com>2025-08-24 01:33:20 +0300
commitcf06bbb2b56690ccfe29e36cbde0d8a68ad04bad (patch)
tree9f139e753139efb9cb4d9a4fd4292ccce756c5f0 /apps/web/lib
parent9df0f44132e19be9fc975543924aef81b04e9e0b (diff)
downloadkarakeep-cf06bbb2b56690ccfe29e36cbde0d8a68ad04bad.tar.zst
fix(web): fix query getting rest when bookmark preview is closed. fixes #1521
Diffstat (limited to 'apps/web/lib')
-rw-r--r--apps/web/lib/hooks/bookmark-search.ts26
-rw-r--r--apps/web/lib/store/useInSearchPageStore.ts13
2 files changed, 24 insertions, 15 deletions
diff --git a/apps/web/lib/hooks/bookmark-search.ts b/apps/web/lib/hooks/bookmark-search.ts
index b6af94ee..0902af44 100644
--- a/apps/web/lib/hooks/bookmark-search.ts
+++ b/apps/web/lib/hooks/bookmark-search.ts
@@ -1,15 +1,12 @@
-import { useEffect, useMemo, useState } from "react";
-import { usePathname, useRouter, useSearchParams } from "next/navigation";
+import { useEffect, useMemo, useRef } from "react";
+import { useRouter, useSearchParams } from "next/navigation";
import { useSortOrderStore } from "@/lib/store/useSortOrderStore";
import { api } from "@/lib/trpc";
import { keepPreviousData } from "@tanstack/react-query";
import { parseSearchQuery } from "@karakeep/shared/searchQueryParser";
-export function useIsSearchPage() {
- const pathname = usePathname();
- return pathname.startsWith("/dashboard/search");
-}
+import { useInSearchPageStore } from "../store/useInSearchPageStore";
function useSearchQuery() {
const searchParams = useSearchParams();
@@ -22,31 +19,30 @@ function useSearchQuery() {
export function useDoBookmarkSearch() {
const router = useRouter();
const { searchQuery, parsedSearchQuery } = useSearchQuery();
- const isInSearchPage = useIsSearchPage();
- const [timeoutId, setTimeoutId] = useState<NodeJS.Timeout | undefined>();
+ const isInSearchPage = useInSearchPageStore((val) => val.inSearchPage);
+ const timeoutId = useRef<NodeJS.Timeout>(null);
useEffect(() => {
return () => {
- if (!timeoutId) {
+ if (!timeoutId.current) {
return;
}
- clearTimeout(timeoutId);
+ clearTimeout(timeoutId.current);
};
}, [timeoutId]);
const doSearch = (val: string) => {
- setTimeoutId(undefined);
+ timeoutId.current = null;
router.replace(`/dashboard/search?q=${encodeURIComponent(val)}`);
};
const debounceSearch = (val: string) => {
- if (timeoutId) {
- clearTimeout(timeoutId);
+ if (timeoutId.current) {
+ clearTimeout(timeoutId.current);
}
- const id = setTimeout(() => {
+ timeoutId.current = setTimeout(() => {
doSearch(val);
}, 10);
- setTimeoutId(id);
};
return {
diff --git a/apps/web/lib/store/useInSearchPageStore.ts b/apps/web/lib/store/useInSearchPageStore.ts
new file mode 100644
index 00000000..c433539d
--- /dev/null
+++ b/apps/web/lib/store/useInSearchPageStore.ts
@@ -0,0 +1,13 @@
+import { create } from "zustand";
+
+interface InSearchPageState {
+ inSearchPage: boolean;
+ setInSearchPage: (inSearchPage: boolean) => void;
+}
+
+export const useInSearchPageStore = create<InSearchPageState>((set) => ({
+ inSearchPage: false,
+ setInSearchPage: (inSearchPage) => {
+ set({ inSearchPage });
+ },
+}));