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.8 KB
Raw Blame
import { MenuItem } from '@invoke-ai/ui-library';
import { useAppSelector } from 'app/store/storeHooks';
import { useDeleteVideoModalApi } from 'features/deleteVideoModal/store/state';
import { useVideoDTOContext } from 'features/gallery/contexts/VideoDTOContext';
import { selectSelection } from 'features/gallery/store/gallerySelectors';
import { isVideoName } from 'features/gallery/store/types';
import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { PiTrashSimpleBold } from 'react-icons/pi';

export const ContextMenuItemDeleteVideo = memo(() => {
  const { t } = useTranslation();
  const videoDTO = useVideoDTOContext();
  const deleteVideoModal = useDeleteVideoModalApi();
  const selection = useAppSelector(selectSelection);

  // When the right-clicked video is part of an active multi-selection, delete every
  // selected video in one shot. Image names mixed into the selection are skipped —
  // right-clicking an image surfaces ImageContextMenu, which owns that flow.
  const targetVideoNames = useMemo(() => {
    if (selection.length > 1 && selection.includes(videoDTO.video_name)) {
      return selection.filter(isVideoName);
    }
    return [videoDTO.video_name];
  }, [selection, videoDTO.video_name]);

  const label = t('gallery.deleteVideo', { count: targetVideoNames.length });

  const onClick = useCallback(async () => {
    try {
      await deleteVideoModal.delete(targetVideoNames);
    } catch {
      // noop — user canceled the confirm dialog.
    }
  }, [deleteVideoModal, targetVideoNames]);

  return (
    <MenuItem color="error.300" icon={<PiTrashSimpleBold />} onClickCapture={onClick}>
      {label}
    </MenuItem>
  );
});

ContextMenuItemDeleteVideo.displayName = 'ContextMenuItemDeleteVideo';