mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
refactored hooks directory
This commit is contained in:
parent
efa3ba902d
commit
f76a5a4798
106 changed files with 122 additions and 144 deletions
46
src/hooks/flow/useFlowCellControls.ts
Normal file
46
src/hooks/flow/useFlowCellControls.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { useCallback } from 'react';
|
||||
import { FlowDisplay, INode } from '~/redux/types';
|
||||
|
||||
export const useFlowCellControls = (
|
||||
id: INode['id'],
|
||||
description: string | undefined,
|
||||
flow: FlowDisplay,
|
||||
onChangeCellView: (id: INode['id'], flow: FlowDisplay) => void
|
||||
) => {
|
||||
const onChange = useCallback(
|
||||
(value: Partial<FlowDisplay>) => onChangeCellView(id, { ...flow, ...value }),
|
||||
[flow, id, onChangeCellView]
|
||||
);
|
||||
|
||||
const hasDescription = !!description && description.length > 32;
|
||||
|
||||
const toggleViewDescription = useCallback(() => {
|
||||
const show_description = !(flow && flow.show_description);
|
||||
onChange({ show_description });
|
||||
}, [flow, onChange]);
|
||||
|
||||
const setViewSingle = useCallback(() => {
|
||||
onChange({ display: 'single' });
|
||||
}, [onChange]);
|
||||
|
||||
const setViewHorizontal = useCallback(() => {
|
||||
onChange({ display: 'horizontal' });
|
||||
}, [onChange]);
|
||||
|
||||
const setViewVertical = useCallback(() => {
|
||||
onChange({ display: 'vertical' });
|
||||
}, [onChange]);
|
||||
|
||||
const setViewQuadro = useCallback(() => {
|
||||
onChange({ display: 'quadro' });
|
||||
}, [onChange]);
|
||||
|
||||
return {
|
||||
hasDescription,
|
||||
setViewHorizontal,
|
||||
setViewVertical,
|
||||
setViewQuadro,
|
||||
setViewSingle,
|
||||
toggleViewDescription,
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue