1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +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

@ -1,44 +1,35 @@
import React, { FC, FormEvent, useCallback, useMemo } from 'react';
import { InputText } from '~/components/input/InputText';
import { FlowRecent } from '../FlowRecent';
import { FlowRecent } from '~/components/flow/FlowRecent';
import styles from './styles.module.scss';
import { FlowSearchResults } from '../FlowSearchResults';
import styles from '~/containers/flow/FlowStamp/styles.module.scss';
import { FlowSearchResults } from '~/components/flow/FlowSearchResults';
import { Icon } from '~/components/input/Icon';
import { Group } from '~/components/containers/Group';
import { Toggle } from '~/components/input/Toggle';
import classNames from 'classnames';
import { Superpower } from '~/components/boris/Superpower';
import { experimentalFeatures } from '~/constants/features';
import { IFlowNode, INode } from '~/redux/types';
import { useSearchContext } from '~/utils/context/SearchContextProvider';
import { useFlowContext } from '~/utils/context/FlowContextProvider';
interface IProps {
searchText: string;
searchTotal: number;
searchIsLoading: boolean;
searchResults: INode[];
onSearchChange: (text: string) => void;
onSearchLoadMore: () => void;
recent: IFlowNode[];
updated: IFlowNode[];
isFluid: boolean;
onToggleLayout: () => void;
}
const FlowStamp: FC<IProps> = ({
searchText,
searchIsLoading,
searchTotal,
searchResults,
onSearchChange,
onSearchLoadMore,
const FlowStamp: FC<IProps> = ({ isFluid, onToggleLayout }) => {
const {
searchText,
searchTotal,
searchIsLoading,
searchResults,
onSearchChange,
onSearchLoadMore,
} = useSearchContext();
const { recent, updates } = useFlowContext();
recent,
updated,
isFluid,
onToggleLayout,
}) => {
const onSearchSubmit = useCallback((event: FormEvent) => {
event.preventDefault();
}, []);
@ -102,7 +93,7 @@ const FlowStamp: FC<IProps> = ({
</div>
<div className={styles.items}>
<FlowRecent updated={updated} recent={recent} />
<FlowRecent updated={updates} recent={recent} />
</div>
</div>
)}

View file

@ -1,4 +1,4 @@
@import "src/styles/variables";
@import "../../../styles/variables";
.wrap {
display: flex;
@ -126,4 +126,4 @@
@include tablet {
margin-top: $gap;
}
}
}

View file

@ -1,48 +1,22 @@
import React, { FC } from 'react';
import { FlowGrid } from '~/components/flow/FlowGrid';
import styles from './styles.module.scss';
import { FlowStamp } from '~/components/flow/FlowStamp';
import { FlowStamp } from '~/containers/flow/FlowStamp';
import { SidebarRouter } from '~/containers/main/SidebarRouter';
import { FlowDisplay, IFlowNode, INode } from '~/redux/types';
import classNames from 'classnames';
import { FlowSwiperHero } from '~/components/flow/FlowSwiperHero';
import { IUser } from '~/redux/auth/types';
import { useFlowContext } from '~/utils/context/FlowContextProvider';
import { useUser } from '~/hooks/user/userUser';
interface Props {
updates: IFlowNode[];
recent: IFlowNode[];
heroes: IFlowNode[];
nodes: IFlowNode[];
user: IUser;
isFluid: boolean;
onToggleLayout: () => void;
onChangeCellView: (id: INode['id'], flow: FlowDisplay) => void;
searchText: string;
searchTotal: number;
searchIsLoading: boolean;
searchResults: INode[];
onSearchChange: (text: string) => void;
onSearchLoadMore: () => void;
}
const FlowLayout: FC<Props> = ({
updates,
heroes,
recent,
nodes,
user,
isFluid,
onToggleLayout,
onChangeCellView,
const FlowLayout: FC<Props> = ({ isFluid, onToggleLayout }) => {
const { heroes, nodes, onChangeCellView } = useFlowContext();
const user = useUser();
searchText,
searchTotal,
searchIsLoading,
searchResults,
onSearchChange,
onSearchLoadMore,
}) => {
return (
<div className={classNames(styles.container)}>
<div className={styles.grid}>
@ -51,18 +25,7 @@ const FlowLayout: FC<Props> = ({
</div>
<div className={styles.stamp}>
<FlowStamp
isFluid={isFluid}
recent={recent}
updated={updates}
searchText={searchText}
searchIsLoading={searchIsLoading}
searchTotal={searchTotal}
searchResults={searchResults}
onSearchChange={onSearchChange}
onSearchLoadMore={onSearchLoadMore}
onToggleLayout={onToggleLayout}
/>
<FlowStamp isFluid={isFluid} onToggleLayout={onToggleLayout} />
</div>
<FlowGrid nodes={nodes} user={user} onChangeCellView={onChangeCellView} />

View file

@ -1,33 +1,26 @@
import React, { FC } from 'react';
import { FlowLayout } from '~/layouts/FlowLayout';
import { useFlow } from '~/hooks/flow/useFlow';
import { useSearch } from '~/hooks/search/useSearch';
import { useUser } from '~/hooks/user/userUser';
import { FlowContextProvider } from '~/utils/context/FlowContextProvider';
import { SearchContextProvider } from '~/utils/context/SearchContextProvider';
interface Props {}
const FlowPage: FC<Props> = () => {
const { updates, nodes, heroes, recent, isFluid, toggleLayout, onChangeCellView } = useFlow();
const user = useUser();
const { search, onSearchLoadMore, onSearchChange } = useSearch();
return (
<FlowLayout
<FlowContextProvider
updates={updates}
recent={recent}
heroes={heroes}
nodes={nodes}
user={user}
isFluid={isFluid}
onToggleLayout={toggleLayout}
onChangeCellView={onChangeCellView}
searchResults={search.results}
searchText={search.text}
searchTotal={search.total}
searchIsLoading={search.is_loading}
onSearchLoadMore={onSearchLoadMore}
onSearchChange={onSearchChange}
/>
>
<SearchContextProvider>
<FlowLayout isFluid={isFluid} onToggleLayout={toggleLayout} />
</SearchContextProvider>
</FlowContextProvider>
);
};

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);