From 5bff39976103077f9aa673f1b531b5669c3be49a Mon Sep 17 00:00:00 2001 From: joaopedro10 Date: Fri, 15 Nov 2024 08:38:19 -0300 Subject: [PATCH] hide personality results while is loading --- .../Personality/PersonalityCreateSearch.tsx | 45 ++++++++++--------- src/components/Search/OverlaySearchInput.tsx | 6 +-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/components/Personality/PersonalityCreateSearch.tsx b/src/components/Personality/PersonalityCreateSearch.tsx index 1085d38df..78563fee1 100644 --- a/src/components/Personality/PersonalityCreateSearch.tsx +++ b/src/components/Personality/PersonalityCreateSearch.tsx @@ -84,18 +84,18 @@ const PersonalityCreateSearch = ({ setIsFormSubmitted(!isFormSubmitted); }; - const handleInputSearch = (name) => { + const handleInputSearch = async (name) => { + setIsLoading(true); const trimmedName = name.trim(); dispatch({ type: ActionTypes.SET_SEARCH_NAME, searchName: trimmedName, }); - setIsLoading(true); - api.getPersonalities( + await api.getPersonalities( { withSuggestions, searchName: trimmedName, i18n }, dispatch - ) - .finally(() => setIsLoading(false)); + ); + setIsLoading(false); }; const personalitiesCreated = personalities.filter( @@ -128,21 +128,26 @@ const PersonalityCreateSearch = ({ /> - {isLoading && } - - + {isLoading ? ( + + ) : ( + <> + + + + )} ); }; diff --git a/src/components/Search/OverlaySearchInput.tsx b/src/components/Search/OverlaySearchInput.tsx index 19bb34e38..9e0ca1bf7 100644 --- a/src/components/Search/OverlaySearchInput.tsx +++ b/src/components/Search/OverlaySearchInput.tsx @@ -22,19 +22,19 @@ const OverlaySearchInput = () => { }; }); - const handleInputSearch = async (searchText) => { + const handleInputSearch = async (name) => { dispatch(actions.isFetchingResults()); dispatch(actions.openResultsOverlay()); dispatch({ type: ActionTypes.SET_SEARCH_OVERLAY_NAME, - searchOverlayInput: searchText, + searchOverlayInput: name, }); const { personalities, sentences, claims } = await SearchApi.getFeedResults({ page, pageSize, - searchText: searchText, + searchText: name, nameSpace: nameSpace, });