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.

988 B
Raw Blame
import type { LogEntry } from '@platform/logging/contracts';

import { LOG_LEVEL_ORDER, matchesLogScope } from '@platform/logging/contracts';
import { getLogSnapshot, subscribeLogs } from '@platform/logging/logger';
import { useCallback, useSyncExternalStore } from 'react';

/** Warnings and above for the project plus application events. */
export const countProblems = (entries: readonly LogEntry[], projectId: string): number => {
  const scope = { kind: 'project-and-application', projectId } as const;
  let count = 0;

  for (const entry of entries) {
    if (LOG_LEVEL_ORDER[entry.level] >= LOG_LEVEL_ORDER.warn && matchesLogScope(entry, scope)) {
      count += 1;
    }
  }

  return count;
};

/** The widget chip and header badge share this count. */
export const useProblemCount = (projectId: string): number => {
  const read = useCallback(() => countProblems(getLogSnapshot().entries, projectId), [projectId]);

  return useSyncExternalStore(subscribeLogs, read, read);
};