Skip to content

Commit

Permalink
prevent saving search when hash is identical
Browse files Browse the repository at this point in the history
  • Loading branch information
lakchote committed Sep 17, 2024
1 parent 0be3fcc commit 6339f05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pages/Search/AdvancedSearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ function AdvancedSearchFilters() {
const {singleExecution} = useSingleExecution();
const waitForNavigate = useWaitForNavigation();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES);
const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);
const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const taxRates = getAllTaxRates();
Expand All @@ -242,6 +243,13 @@ function AdvancedSearchFilters() {
};

const onSaveSearch = () => {
const savedSearchKeys = Object.keys(savedSearches ?? {});
if (savedSearches && savedSearchKeys.includes(String(queryJSON.hash))) {
// If the search is already saved, return early to prevent unnecessary API calls
Navigation.dismissModal();
return;
}

SearchActions.saveSearch({
queryJSON,
});
Expand Down

0 comments on commit 6339f05

Please sign in to comment.