Skip to content

The open alternative to Salesforce, designed for AI.

1.1 KB
Raw Blame
import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';
import { useStore } from 'jotai';
import { useCallback } from 'react';
import { pageLayoutSelectedCellsComponentState } from '@/page-layout/states/pageLayoutSelectedCellsComponentState';

export const useStartPageLayoutDragSelection = (
  pageLayoutIdFromProps?: string,
) => {
  const pageLayoutId = useAvailableComponentInstanceIdOrThrow(
    PageLayoutComponentInstanceContext,
    pageLayoutIdFromProps,
  );

  const pageLayoutSelectedCellsState = useAtomComponentStateCallbackState(
    pageLayoutSelectedCellsComponentState,
    pageLayoutId,
  );

  const store = useStore();

  const startPageLayoutDragSelection = useCallback(() => {
    store.set(pageLayoutSelectedCellsState, new Set());
  }, [pageLayoutSelectedCellsState, store]);

  return { startPageLayoutDragSelection };
};