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.0 KB
Raw Blame
import type { GraphPreviewInvokeScopeProps } from '@workbench/widget-frame/graphPreviewInvoke';

import { useCallback, useMemo } from 'react';

import { InvokeButton } from './InvokeButton';
import { type InvocationState, useInvocationState } from './useInvocationState';

/** A graph preview's Invoke: the top bar's control for the previewed source's route, not the active one. */
export const GraphPreviewInvokeScope = ({ render, sourceId, onOpenChange }: GraphPreviewInvokeScopeProps) => {
  const state = useInvocationState({ sourceId });
  const close = useCallback(() => onOpenChange(false), [onOpenChange]);
  const { invoke, isValid } = state;
  const previewState = useMemo<InvocationState>(
    () => ({ ...state, invoke: (options) => invoke({ ...options, onStarted: close }) }),
    [close, invoke, state]
  );
  const slot = useMemo(
    () => ({
      control: <InvokeButton isRouteFixed size="md" state={previewState} onJump={close} />,
      isReady: isValid,
    }),
    [close, isValid, previewState]
  );

  return render(slot);
};