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.

939 B
Raw Blame
import { useBuildWorkflowFast } from 'features/nodes/util/workflow/buildWorkflow';
import { saveWorkflowAs } from 'features/workflowLibrary/components/SaveWorkflowAsDialog';
import { isLibraryWorkflow, useSaveLibraryWorkflow } from 'features/workflowLibrary/hooks/useSaveLibraryWorkflow';
import { useCallback } from 'react';

/**
 * Returns a function that saves the current workflow if it's a library workflow, or opens the save as dialog.
 *
 * Published workflows are always saved as a new workflow.
 */
export const useSaveOrSaveAsWorkflow = () => {
  const buildWorkflow = useBuildWorkflowFast();
  const { saveWorkflow } = useSaveLibraryWorkflow();

  const saveOrSaveAsWorkflow = useCallback(() => {
    const workflow = buildWorkflow();

    if (isLibraryWorkflow(workflow)) {
      saveWorkflow(workflow);
    } else {
      saveWorkflowAs(workflow);
    }
  }, [buildWorkflow, saveWorkflow]);

  return saveOrSaveAsWorkflow;
};