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:
parent
31e433af3e
commit
5f3accee48
6 changed files with 105 additions and 87 deletions
25
src/utils/context/FlowContextProvider.tsx
Normal file
25
src/utils/context/FlowContextProvider.tsx
Normal 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);
|
46
src/utils/context/SearchContextProvider.tsx
Normal file
46
src/utils/context/SearchContextProvider.tsx
Normal 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);
|
Loading…
Add table
Add a link
Reference in a new issue