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.3 KB
Raw Blame
import { getDeterminateProgressPercent } from '@features/queue/contracts';
import { useMountEffect } from '@platform/react/useMountEffect';
import { useActiveQueueProgress } from '@workbench/queue-integration/useActiveQueueProgress';
import { useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { DOCUMENT_TITLE_BASE, formatDocumentTitle } from './documentTitle';

/** Write rounded progress to document.title to avoid updating on every progress frame. */
export const DocumentTitleProgress = () => {
  const { t } = useTranslation();
  const { progress, summary } = useActiveQueueProgress();
  const { current, total } = summary;
  const percent = getDeterminateProgressPercent(progress?.percentage);

  const title = useMemo(
    () =>
      formatDocumentTitle({
        current,
        labels: { generating: t('common.generating'), queued: t('widgets.queueStatus.queued', { count: total }) },
        percent,
        total,
      }),
    [current, percent, t, total]
  );

  useEffect(() => {
    document.title = title;
  }, [title]);

  // Separate from the write above so switching titles does not flash the base one in between; this only runs when the
  // shell itself goes away.
  useMountEffect(() => () => {
    document.title = DOCUMENT_TITLE_BASE;
  });

  return null;
};