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:
parent
cac97e87f0
commit
35ce593ed8
8 changed files with 72 additions and 44 deletions
19
src/utils/hooks/flow/useFlowLayout.ts
Normal file
19
src/utils/hooks/flow/useFlowLayout.ts
Normal 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 };
|
||||
};
|
23
src/utils/hooks/flow/useFlowPagination.ts
Normal file
23
src/utils/hooks/flow/useFlowPagination.ts
Normal 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]);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue