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

moved flow hooks out of flow

This commit is contained in:
Fedor Katurov 2021-09-20 10:01:59 +07:00
parent cac97e87f0
commit 35ce593ed8
8 changed files with 72 additions and 44 deletions

View file

@ -0,0 +1,19 @@
import { useCallback } from 'react';
import { usePersistedState } from '~/utils/hooks/usePersistedState';
import { experimentalFeatures } from '~/constants/features';
enum Layout {
Fluid = 'fluid',
Default = 'default',
}
export const useFlowLayout = () => {
const [layout, setLayout] = usePersistedState('flow_layout', Layout.Default);
const isFluid = layout === Layout.Fluid && experimentalFeatures.liquidFlow;
const toggleLayout = useCallback(() => {
setLayout(isFluid ? Layout.Default : Layout.Fluid);
}, [setLayout, isFluid]);
return { isFluid, toggleLayout };
};

View file

@ -0,0 +1,23 @@
import { useCallback, useEffect } from 'react';
import { flowGetMore } from '~/redux/flow/actions';
import { useDispatch } from 'react-redux';
export const useFlowPagination = ({ isLoading }) => {
const dispatch = useDispatch();
const onLoadMore = useCallback(() => {
(window as any).flowScrollPos = window.scrollY;
const pos = window.scrollY + window.innerHeight - document.body.scrollHeight;
if (isLoading || pos < -600) return;
dispatch(flowGetMore());
}, [dispatch, isLoading]);
useEffect(() => {
window.addEventListener('scroll', onLoadMore);
return () => window.removeEventListener('scroll', onLoadMore);
}, [onLoadMore]);
};