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.

973 B
Raw Blame
import { useStore } from '@nanostores/react';
import { $hasTemplates } from 'features/nodes/store/nodesSlice';
import { useLoadWorkflowWithDialog } from 'features/workflowLibrary/components/LoadWorkflowConfirmationAlertDialog';
import { useCallback, useMemo } from 'react';
import type { ImageDTO } from 'services/api/types';

export const useLoadWorkflow = (imageDTO: ImageDTO) => {
  const hasTemplates = useStore($hasTemplates);

  const loadWorkflowWithDialog = useLoadWorkflowWithDialog();

  const isEnabled = useMemo(() => {
    if (!imageDTO.has_workflow) {
      return false;
    }
    if (!hasTemplates) {
      return false;
    }
    return true;
  }, [hasTemplates, imageDTO]);

  const load = useCallback(() => {
    if (!imageDTO) {
      return;
    }
    if (!isEnabled) {
      return;
    }

    loadWorkflowWithDialog({ type: 'image', data: imageDTO.image_name });
  }, [imageDTO, isEnabled, loadWorkflowWithDialog]);

  return { load, isEnabled };
};