Skip to content

Commit

Permalink
reset search store on search bar unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Nov 17, 2023
1 parent b6e7bd5 commit 5f75214
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion interface/app/$libraryId/Explorer/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CaretRight, FunnelSimple, Icon, Plus } from '@phosphor-icons/react';
import { IconTypes } from '@sd/assets/util';
import clsx from 'clsx';
import { memo, PropsWithChildren, useDeferredValue, useState } from 'react';
import { memo, PropsWithChildren, useDeferredValue, useEffect, useState } from 'react';
import { Button, ContextMenuDivItem, DropdownMenu, Input, RadixCheckbox, tw } from '@sd/ui';
import { useKeybind } from '~/hooks';

Expand All @@ -10,6 +10,7 @@ import { useSearchContext } from './Context';
import { filterRegistry, SearchFilterCRUD, useToggleOptionSelected } from './Filters';
import {
getSearchStore,
resetSearchStore,
useRegisterSearchFilterOptions,
useSearchRegisteredFilters,
useSearchStore
Expand Down Expand Up @@ -92,6 +93,10 @@ const SearchOptions = () => {
useRegisterSearchFilterOptions(filter, options);
}

useEffect(() => {
return () => resetSearchStore();
}, []);

return (
<div
onMouseEnter={() => {
Expand Down
1 change: 1 addition & 0 deletions interface/app/$libraryId/Explorer/Search/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const useSearchRegisteredFilters = (query: string) => {
export const resetSearchStore = () => {
searchStore.searchQuery = null;
searchStore.filterArgs = ref([]);
searchStore.filterArgsKeys = ref(new Set());
};

export const useSearchStore = () => useSnapshot(searchStore);
Expand Down

0 comments on commit 5f75214

Please sign in to comment.