-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(searchbox): Enhance search context and search box functionalities
- Add error and loading state to SearchContext to manage search status and error handling - Update SearchBox to include InputHTMLAttributes for better flexibility in input handling - Adjust useSearchBox hook to set error and loading states in SearchContext - Restructure imports for better readability in search.context.tsx - Reorder and adjust SearchBoxProps to move debounceDelay configuration - Export necessary hooks and context from the search index file for unified module access
- Loading branch information
Showing
5 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import { SearchResponse } from '@bloomreach/discovery-web-sdk'; | ||
import { Dispatch, PropsWithChildren, ReactElement, SetStateAction, createContext, useState } from 'react'; | ||
import { | ||
Dispatch, | ||
PropsWithChildren, | ||
ReactElement, | ||
SetStateAction, | ||
createContext, | ||
useState, | ||
} from 'react'; | ||
|
||
export type SearchContextType = { | ||
error: unknown; | ||
loading: boolean; | ||
searchResponse: SearchResponse | null; | ||
setError: Dispatch<SetStateAction<unknown>>; | ||
setLoading: Dispatch<SetStateAction<boolean>>; | ||
setSearchResponse: Dispatch<SetStateAction<SearchResponse | null>>; | ||
}; | ||
|
||
export const SearchContext = createContext<SearchContextType>({ | ||
error: null, | ||
loading: false, | ||
searchResponse: null, | ||
setError: () => {}, | ||
setLoading: () => {}, | ||
setSearchResponse: () => {}, | ||
}); | ||
|
||
export const SearchContextProvider = ({ children }: PropsWithChildren): ReactElement => { | ||
const [searchResponse, setSearchResponse] = useState<SearchResponse | null>(null); | ||
const contextValue = { searchResponse, setSearchResponse }; | ||
const [error, setError] = useState<unknown>(null); | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const contextValue = { searchResponse, setSearchResponse, error, setError, loading, setLoading }; | ||
|
||
return <SearchContext.Provider value={contextValue}>{children}</SearchContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export { SearchBox } from './search-box/search-box'; | ||
export type { SearchBoxProps } from './search-box/search-box.types'; | ||
export { SearchBox } from './search-box/search-box'; | ||
export { useSearchBox } from './search-box/search-box.hook'; | ||
export { useSearch } from './hooks/search.hook'; | ||
export { SearchContext, SearchContextProvider, type SearchContextType } from './context/search.context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters