Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

1.4 KB
Raw Blame
import { useDndContext, useDroppable } from '@dnd-kit/core';
import { isGalleryImageDragData } from '@features/gallery/utility';
import { DropZone } from '@platform/ui/DropZone';
import { DropZoneLabel } from '@workbench/widgets/shared/DropZoneLabel';
import { useTranslation } from 'react-i18next';

import { PREVIEW_COMPARE_DROP_DATA, PREVIEW_COMPARE_DROP_ID } from './previewCompareDnd';

/** Image-only drags; the first item is refused if shown, so self-comparison cannot pause live-follow. */
export const PreviewCompareDropZone = ({ currentImageName }: { currentImageName: string | null }) => {
  const { t } = useTranslation();
  const { active } = useDndContext();
  const activeData = active?.data.current;
  const isCompatible = isGalleryImageDragData(activeData);
  const isSelfCompare = isCompatible && activeData.items[0]?.name === currentImageName;
  const { isOver, setNodeRef } = useDroppable({
    data: PREVIEW_COMPARE_DROP_DATA,
    disabled: !isCompatible || isSelfCompare,
    id: PREVIEW_COMPARE_DROP_ID,
  });

  if (!isCompatible || isSelfCompare) {
    return null;
  }

  return (
    <DropZone
      ref={setNodeRef}
      alignItems="center"
      display="flex"
      inset="1"
      isOver={isOver}
      justifyContent="center"
      opacity={isOver ? 1 : 0.85}
      position="absolute"
      rounded="lg"
      variant="overlay"
      zIndex="2"
    >
      <DropZoneLabel>{t('widgets.preview.dropToCompare')}</DropZoneLabel>
    </DropZone>
  );
};