mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
moved flow hooks out of flow
This commit is contained in:
parent
cac97e87f0
commit
35ce593ed8
8 changed files with 72 additions and 44 deletions
|
@ -19,28 +19,17 @@ import { INode } from '~/redux/types';
|
|||
import { selectLabUpdatesNodes } from '~/redux/lab/selectors';
|
||||
import { usePersistedState } from '~/utils/hooks/usePersistedState';
|
||||
import classNames from 'classnames';
|
||||
|
||||
enum Layout {
|
||||
Fluid = 'fluid',
|
||||
Default = 'default',
|
||||
}
|
||||
import { useFlowLayout } from '~/utils/hooks/flow/useFlowLayout';
|
||||
import { useFlowPagination } from '~/utils/hooks/flow/useFlowPagination';
|
||||
|
||||
const FlowLayout: FC = () => {
|
||||
const { nodes, heroes, recent, updated, is_loading, search } = useShallowSelect(selectFlow);
|
||||
const [layout, setLayout] = usePersistedState('flow_layout', Layout.Default);
|
||||
const { nodes, heroes, recent, updated, isLoading, search } = useShallowSelect(selectFlow);
|
||||
const { isFluid, toggleLayout } = useFlowLayout();
|
||||
const labUpdates = useShallowSelect(selectLabUpdatesNodes);
|
||||
const user = useShallowSelect(selectUser);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const onLoadMore = useCallback(() => {
|
||||
(window as any).flowScrollPos = window.scrollY;
|
||||
|
||||
const pos = window.scrollY + window.innerHeight - document.body.scrollHeight;
|
||||
|
||||
if (is_loading || pos < -600) return;
|
||||
|
||||
dispatch(flowGetMore());
|
||||
}, [dispatch, is_loading]);
|
||||
useFlowPagination({ isLoading });
|
||||
|
||||
const onLoadMoreSearch = useCallback(() => {
|
||||
if (search.is_loading_more) return;
|
||||
|
@ -66,17 +55,6 @@ const FlowLayout: FC = () => {
|
|||
labUpdates,
|
||||
]);
|
||||
|
||||
const isFluid = layout === Layout.Fluid;
|
||||
const toggleLayout = useCallback(() => {
|
||||
setLayout(isFluid ? Layout.Default : Layout.Fluid);
|
||||
}, [setLayout, isFluid]);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('scroll', onLoadMore);
|
||||
|
||||
return () => window.removeEventListener('scroll', onLoadMore);
|
||||
}, [onLoadMore]);
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo(0, (window as any).flowScrollPos || 0);
|
||||
}, []);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue