Skip to content

Commit

Permalink
refactoring after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Oct 25, 2024
1 parent 1b94e00 commit f4f9dea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/common/hooks/useFetchSearchData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react';
import { useSetRecoilState, useRecoilState, SetterOrUpdater } from 'recoil';
import { useSetRecoilState, useRecoilState, SetterOrUpdater, useResetRecoilState } from 'recoil';
import { getByIdentifier } from '@common/api/search.api';
import { SearchIdentifiers, SearchSegment } from '@common/constants/search.constants';
import { SearchableIndexQuerySelector } from '@common/constants/complexLookup.constants';
Expand All @@ -10,7 +10,7 @@ import { UserNotificationFactory } from '@common/services/userNotification';
import state from '@state';
import { useSearchContext } from './useSearchContext';

export const useFetchSearhData = () => {
export const useFetchSearchData = () => {
const {
endpointUrl,
searchFilter,
Expand All @@ -27,8 +27,10 @@ export const useFetchSearhData = () => {
const setIsLoading = useSetRecoilState(state.loadingState.isLoading);
const setMessage = useSetRecoilState(state.search.message);
const [data, setData] = useRecoilState(state.search.data);
const resetData = useResetRecoilState(state.search.data);
const setPageMetadata = useSetRecoilState(state.search.pageMetadata);
const setStatusMessages = useSetRecoilState(state.status.commonMessages);
const resetStatusMessage = useResetRecoilState(state.status.commonMessages);

const validateAndNormalizeQuery = useCallback(
(type: SearchIdentifiers, query: string) => {
Expand Down Expand Up @@ -143,10 +145,10 @@ export const useFetchSearhData = () => {
selectedSegment,
baseQuerySelector = SearchableIndexQuerySelector.Query,
}: FetchDataParams) => {
setMessage('');
resetStatusMessage();
const selectedNavigationSegment = selectedSegment ?? navigationSegment?.value;

data && setData(null);
data && resetData();

const updatedQuery = validateAndNormalizeQuery(searchBy, query);
if (!updatedQuery) return;
Expand Down
4 changes: 2 additions & 2 deletions src/common/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { generateSearchParamsState } from '@common/helpers/search.helper';
import { usePagination } from '@common/hooks/usePagination';
import state from '@state';
import { useSearchContext } from './useSearchContext';
import { useFetchSearhData } from './useFetchSearchData';
import { useFetchSearchData } from './useFetchSearchData';

export const useSearch = () => {
const {
Expand All @@ -32,7 +32,7 @@ export const useSearch = () => {
const [facetsBySegments, setFacetsBySegments] = useRecoilState(state.search.facetsBySegments);
const clearFacetsBySegments = useResetRecoilState(state.search.facetsBySegments);

const { fetchData } = useFetchSearhData();
const { fetchData } = useFetchSearchData();
const {
getCurrentPageNumber,
setCurrentPageNumber,
Expand Down

0 comments on commit f4f9dea

Please sign in to comment.