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.6 KB
Raw Blame
import type { WidgetViewProps } from '@workbench/widgetContracts';

import { Stack, Text } from '@chakra-ui/react';
import { StatusWidgetChip } from '@workbench/widget-frame';
import { useWorkbenchSelector } from '@workbench/WorkbenchContext';
import { CircleXIcon, PlugZapIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';

export const ServerStatusWidgetView = ({ presentation }: WidgetViewProps) => {
  const { t } = useTranslation();
  const backendConnection = useWorkbenchSelector((snapshot) => snapshot.backendConnection);
  const isConnected = backendConnection.status === 'connected';
  const isDisconnected = backendConnection.status === 'disconnected';
  const label = isConnected
    ? t('widgets.serverStatus.connected')
    : isDisconnected
      ? t('widgets.serverStatus.disconnected')
      : t('widgets.serverStatus.connecting');

  if (presentation === 'tooltip') {
    return (
      <Stack gap="2">
        <Text fontSize="md" fontWeight="700">
          {t('widgets.serverStatus.label')}
        </Text>
        <Text color="fg.subtle" fontSize="xs">
          {backendConnection.error
            ? t('widgets.serverStatus.labelWithError', { error: backendConnection.error, label })
            : label}
        </Text>
      </Stack>
    );
  }

  if (isDisconnected) {
    return (
      <StatusWidgetChip hiddenLabel={t('widgets.labels.serverStatus')} icon={CircleXIcon} tone="error">
        {label}
      </StatusWidgetChip>
    );
  }

  return (
    <StatusWidgetChip hiddenLabel={t('widgets.labels.serverStatus')} icon={PlugZapIcon}>
      {label}
    </StatusWidgetChip>
  );
};