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.

1006 B
Raw Blame
import { useAppSelector, useAppStore } from 'app/store/storeHooks';
import { useCanvasIsStaging } from 'features/controlLayers/store/canvasStagingAreaSlice';
import { MetadataUtils } from 'features/metadata/parsing';
import { selectActiveTab } from 'features/ui/store/uiSelectors';
import { useCallback, useMemo } from 'react';
import type { ImageDTO } from 'services/api/types';

export const useRecallDimensions = (imageDTO: ImageDTO) => {
  const store = useAppStore();
  const tab = useAppSelector(selectActiveTab);
  const isStaging = useCanvasIsStaging();

  const isEnabled = useMemo(() => {
    if (tab !== 'canvas' && tab !== 'generate') {
      return false;
    }

    if (tab === 'canvas' && isStaging) {
      return false;
    }

    return true;
  }, [isStaging, tab]);

  const recall = useCallback(() => {
    if (!isEnabled) {
      return;
    }
    MetadataUtils.recallImageDimensions(imageDTO, store);
  }, [isEnabled, imageDTO, store]);

  return {
    recall,
    isEnabled,
  };
};