mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
moved search provider to the top of the app
This commit is contained in:
parent
31fc033d4f
commit
7dfa6f89c7
4 changed files with 13 additions and 12 deletions
|
@ -1,42 +0,0 @@
|
|||
import React, { createContext, FC, useContext } from 'react';
|
||||
import { INode } from '~/redux/types';
|
||||
import { useSearch } from '~/hooks/search/useSearch';
|
||||
|
||||
export interface SearchContextProps {
|
||||
searchText: string;
|
||||
hasMore: boolean;
|
||||
searchIsLoading: boolean;
|
||||
searchResults: INode[];
|
||||
setSearchText: (text: string) => void;
|
||||
loadMore: () => void;
|
||||
}
|
||||
|
||||
export const SearchContext = createContext<SearchContextProps>({
|
||||
searchText: '',
|
||||
hasMore: false,
|
||||
searchIsLoading: false,
|
||||
searchResults: [],
|
||||
setSearchText: () => {},
|
||||
loadMore: () => {},
|
||||
});
|
||||
|
||||
export const SearchContextProvider: FC = ({ children }) => {
|
||||
const { results, searchText, isLoading, loadMore, setSearchText, hasMore } = useSearch();
|
||||
|
||||
return (
|
||||
<SearchContext.Provider
|
||||
value={{
|
||||
searchText,
|
||||
searchResults: results,
|
||||
searchIsLoading: isLoading,
|
||||
hasMore,
|
||||
setSearchText,
|
||||
loadMore,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</SearchContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useSearchContext = () => useContext(SearchContext);
|
Loading…
Add table
Add a link
Reference in a new issue