From 9bab6a498266983c29fc747be7eeba93b0fbf700 Mon Sep 17 00:00:00 2001 From: Raul Kele Date: Fri, 14 Oct 2022 15:27:21 +0300 Subject: [PATCH] change search border color if search failed Signed-off-by: Raul Kele --- src/components/SearchSuggestion.jsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/SearchSuggestion.jsx b/src/components/SearchSuggestion.jsx index 57f00dbc..4f652c52 100644 --- a/src/components/SearchSuggestion.jsx +++ b/src/components/SearchSuggestion.jsx @@ -7,7 +7,7 @@ import { api, endpoints } from 'api'; import { host } from 'host'; import { mapToRepo } from 'utilities/objectModels'; import { createSearchParams, useNavigate } from 'react-router-dom'; -import { debounce } from 'lodash'; +import { debounce, isEmpty } from 'lodash'; import { useCombobox } from 'downshift'; const useStyles = makeStyles(() => ({ @@ -29,6 +29,15 @@ const useStyles = makeStyles(() => ({ borderRadius: '2.5rem', zIndex: 1155 }, + searchFailed: { + position: 'relative', + minWidth: '100%', + flexDirection: 'row', + boxShadow: '0rem 0.3125rem 0.625rem rgba(131, 131, 131, 0.08)', + border: '0.125rem solid #ff0303', + borderRadius: '2.5rem', + zIndex: 1155 + }, resultsWrapper: { margin: '0', marginTop: '-2%', @@ -74,6 +83,8 @@ const useStyles = makeStyles(() => ({ function SearchSuggestion() { const [searchQuery, setSearchQuery] = useState(''); const [suggestionData, setSuggestionData] = useState([]); + const [isLoading, setIsLoading] = useState(false); + const [isFailedSearch, setIsFailedSearch] = useState(false); const navigate = useNavigate(); const abortController = useMemo(() => new AbortController(), []); const classes = useStyles(); @@ -94,6 +105,8 @@ function SearchSuggestion() { const value = event.inputValue; setSearchQuery(value); if (value !== '' && value.length > 1) { + setIsLoading(true); + setIsFailedSearch(false); api .get( `${host()}${endpoints.globalSearch({ searchQuery: value, pageNumber: 1, pageSize: 9 })}`, @@ -103,10 +116,15 @@ function SearchSuggestion() { if (suggestionResponse.data.data.GlobalSearch.Repos) { const suggestionParsedData = suggestionResponse.data.data.GlobalSearch.Repos.map((el) => mapToRepo(el)); setSuggestionData(suggestionParsedData); + if (isEmpty(suggestionParsedData)) { + setIsFailedSearch(true); + } } + setIsLoading(false); }) .catch((e) => { console.error(e); + setIsLoading(false); }); } }; @@ -158,7 +176,7 @@ function SearchSuggestion() { return (