From 02a5b35a30845268cfaa814bb045d0ec800dc538 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sat, 12 Oct 2024 13:21:40 +0000 Subject: fix(web): Reset search query and bulk edit when navigating away from the current page --- .../web/components/dashboard/BulkBookmarksAction.tsx | 11 +++++++++-- apps/web/components/dashboard/search/SearchInput.tsx | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'apps/web/components/dashboard') diff --git a/apps/web/components/dashboard/BulkBookmarksAction.tsx b/apps/web/components/dashboard/BulkBookmarksAction.tsx index 39e13940..c78b65db 100644 --- a/apps/web/components/dashboard/BulkBookmarksAction.tsx +++ b/apps/web/components/dashboard/BulkBookmarksAction.tsx @@ -1,6 +1,7 @@ "use client"; import React, { useEffect, useState } from "react"; +import { usePathname } from "next/navigation"; import { ActionButton, ActionButtonWithTooltip, @@ -47,10 +48,16 @@ export default function BulkBookmarksAction() { const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); const [manageListsModal, setManageListsModalOpen] = useState(false); const [bulkTagModal, setBulkTagModalOpen] = useState(false); + const pathname = usePathname(); + const [currentPathname, setCurrentPathname] = useState(""); + // Reset bulk edit state when the route changes useEffect(() => { - setIsBulkEditEnabled(false); // turn off toggle + clear selected bookmarks on mount - }, []); + if (pathname !== currentPathname) { + setCurrentPathname(pathname); + setIsBulkEditEnabled(false); + } + }, [pathname, currentPathname]); const onError = () => { toast({ diff --git a/apps/web/components/dashboard/search/SearchInput.tsx b/apps/web/components/dashboard/search/SearchInput.tsx index 0dd86c50..bab51ff2 100644 --- a/apps/web/components/dashboard/search/SearchInput.tsx +++ b/apps/web/components/dashboard/search/SearchInput.tsx @@ -1,6 +1,6 @@ "use client"; -import React from "react"; +import React, { useEffect } from "react"; import { Input } from "@/components/ui/input"; import { useDoBookmarkSearch } from "@/lib/hooks/bookmark-search"; @@ -8,14 +8,28 @@ const SearchInput = React.forwardRef< HTMLInputElement, React.HTMLAttributes & { loading?: boolean } >(({ className, ...props }, ref) => { - const { debounceSearch, searchQuery } = useDoBookmarkSearch(); + const { debounceSearch, searchQuery, isInSearchPage } = useDoBookmarkSearch(); + + const [value, setValue] = React.useState(searchQuery); + + useEffect(() => { + if (!isInSearchPage) { + setValue(""); + } + }, [isInSearchPage]); + + const onChange = (e: React.ChangeEvent) => { + setValue(e.target.value); + debounceSearch(e.target.value); + }; return ( debounceSearch(e.target.value)} className={className} {...props} /> -- cgit v1.2.3-70-g09d2