1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

added flow context

This commit is contained in:
Fedor Katurov 2022-01-04 13:44:51 +07:00
parent 31e433af3e
commit 5f3accee48
6 changed files with 105 additions and 87 deletions

View file

@ -0,0 +1,25 @@
import React, { createContext, FC, useContext } from 'react';
import { FlowDisplay, IFlowNode, INode } from '~/redux/types';
export interface FlowContextProps {
updates: IFlowNode[];
recent: IFlowNode[];
heroes: IFlowNode[];
nodes: IFlowNode[];
onChangeCellView: (id: INode['id'], flow: FlowDisplay) => void;
}
export const FlowContext = createContext<FlowContextProps>({
updates: [],
recent: [],
heroes: [],
nodes: [],
onChangeCellView: () => {},
});
export const FlowContextProvider: FC<FlowContextProps> = ({ children, ...contextValue }) => {
return <FlowContext.Provider value={contextValue}>{children}</FlowContext.Provider>;
};
export const useFlowContext = () => useContext(FlowContext);

View file

@ -0,0 +1,46 @@
import React, { createContext, FC, useContext } from 'react';
import { INode } from '~/redux/types';
import { useSearch } from '~/hooks/search/useSearch';
export interface SearchContextProps {
searchText: string;
searchTotal: number;
searchIsLoading: boolean;
searchResults: INode[];
onSearchChange: (text: string) => void;
onSearchLoadMore: () => void;
}
export const SearchContext = createContext<SearchContextProps>({
searchText: '',
searchTotal: 0,
searchIsLoading: false,
searchResults: [],
onSearchChange: () => {},
onSearchLoadMore: () => {},
});
export const SearchContextProvider: FC = ({ children }) => {
const {
search: { text, results, is_loading, total },
onSearchLoadMore,
onSearchChange,
} = useSearch();
return (
<SearchContext.Provider
value={{
searchText: text,
searchResults: results,
searchIsLoading: is_loading,
searchTotal: total,
onSearchChange,
onSearchLoadMore,
}}
>
{children}
</SearchContext.Provider>
);
};
export const useSearchContext = () => useContext(SearchContext);