1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00
vault-frontend/src/hooks/flow/useFlowCellControls.ts
2025-01-24 17:51:59 +07:00

48 lines
1.2 KiB
TypeScript

import { useCallback } from 'react';
import { FlowDisplay, INode } from '~/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,
};
};