diff --git a/src/pages/Search/SearchSavePage.tsx b/src/pages/Search/SearchSavePage.tsx index fcfd05c1c2ce..42fa73ce3ce8 100644 --- a/src/pages/Search/SearchSavePage.tsx +++ b/src/pages/Search/SearchSavePage.tsx @@ -83,25 +83,19 @@ function FilterValue({filterKey, value}: FilterValueWithKeyProps) { function SearchSavePage() { const styles = useThemeStyles(); const {translate, localeCompare} = useLocalize(); - const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES); const [searchAdvancedFiltersForm = getEmptyObject>()] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); const [name, setName] = useState(''); const {currentSearchQueryJSON} = useSearchStateContext(); const onSaveSearch = () => { - const savedSearchKeys = Object.keys(savedSearches ?? {}); - if (!currentSearchQueryJSON || (savedSearches && savedSearchKeys.includes(String(currentSearchQueryJSON.hash)))) { - // If the search is already saved, we only display the results as we don't need to save it. + if (!currentSearchQueryJSON) { Navigation.goBack(); return; } - if (name) { - saveSearch({queryJSON: currentSearchQueryJSON, newName: name}); - } else { - saveSearch({queryJSON: currentSearchQueryJSON}); - } + const newName = name.trim() || currentSearchQueryJSON?.inputQuery; + saveSearch({queryJSON: currentSearchQueryJSON, newName}); Navigation.goBack(); };