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.8 KB
Raw Blame
import { chakra, Icon, Menu } from '@chakra-ui/react';
import { apiFetchJson } from '@platform/transport/http';
import { type QueryClient, queryOptions, useQuery } from '@tanstack/react-query';
import { HeartIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';

interface FrontendConfig {
  show_donation_link: boolean;
}

const frontendConfigQueryOptions = queryOptions({
  queryKey: ['frontend-config'],
  queryFn: ({ signal }) => apiFetchJson<FrontendConfig>('/api/v1/app/frontend_config', { signal }),
  staleTime: Infinity,
});

/** Called on trigger hover and focus so the setting resolves before the menu opens; also retries failures. */
export const prefetchDonationMenuItem = (queryClient: QueryClient) =>
  queryClient.prefetchQuery(frontendConfigQueryOptions);

export interface DonationMenuItemProps {
  /** Leads with its own separator where the link forms a group of one, so a hidden link leaves no separator behind. */
  separated?: boolean;
}

/** Both menus share the server's visibility policy and the same external destination. */
export const DonationMenuItem = ({ separated = false }: DonationMenuItemProps) => {
  const { t } = useTranslation();
  const { data } = useQuery(frontendConfigQueryOptions);

  // Keep the optional link hidden until the deployment's preference is known, including on request failure.
  if (!data?.show_donation_link) {
    return null;
  }

  return (
    <>
      {separated ? <Menu.Separator /> : null}
      <Menu.Item asChild value="donate">
        <chakra.a href="https://github.com/sponsors/invoke-ai" rel="noreferrer" target="_blank">
          <Icon as={HeartIcon} boxSize="3.5" />
          <Menu.ItemText>{t('common.donateToInvokeAI')}</Menu.ItemText>
        </chakra.a>
      </Menu.Item>
    </>
  );
};