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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import type { GalleryBoard } from '@features/gallery/core/types';
import type { TFunction } from 'i18next';
import { Icon } from '@chakra-ui/react';
import { canOnBoard } from '@features/gallery/core/boardAccess';
import { getGalleryBoardLabel } from '@features/gallery/core/boardLabels';
import { ALL_READABLE_BOARDS_ID } from '@features/gallery/core/items';
import { isDateBoardId } from '@features/gallery/data/backend';
import { IconButton } from '@platform/ui/Button';
import { Tooltip } from '@platform/ui/Tooltip';
import { UploadIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useGalleryUploadInput } from './useGalleryUploadInput';
/** Tooltip/aria text for an upload control on the listing's board; unavailable when it takes no uploads. */
export const getGalleryUploadTargetLabel = (
boards: readonly GalleryBoard[],
selectedBoardId: string,
t: TFunction
): { isAvailable: boolean; label: string } => {
if (selectedBoardId === ALL_READABLE_BOARDS_ID) {
return { isAvailable: false, label: t('widgets.gallery.uploadsUnavailableForAllBoards') };
}
if (isDateBoardId(selectedBoardId)) {
return { isAvailable: false, label: t('widgets.gallery.uploadsUnavailableForDateBoards') };
}
const selectedBoard = boards.find((board) => board.id === selectedBoardId);
if (selectedBoard && !canOnBoard(selectedBoard, 'add_media')) {
return {
isAvailable: false,
label: t('widgets.gallery.uploadsUnavailableForViewOnlyBoard', { name: getGalleryBoardLabel(selectedBoard, t) }),
};
}
return {
isAvailable: true,
label: t('widgets.gallery.uploadMediaToBoard', {
name: selectedBoard ? getGalleryBoardLabel(selectedBoard, t) : t('widgets.gallery.selectedBoardFallback'),
}),
};
};
export const GalleryUploadButton = ({
boards,
selectedBoardId,
onUploadFiles,
}: {
boards: GalleryBoard[];
selectedBoardId: string;
onUploadFiles: (files: File[]) => Promise<unknown>;
}) => {
const { t } = useTranslation();
const { isAvailable, label } = getGalleryUploadTargetLabel(boards, selectedBoardId, t);
const { inputProps, openPicker } = useGalleryUploadInput(onUploadFiles);
return (
<>
<input {...inputProps} />
<Tooltip content={label}>
<IconButton aria-label={label} color="fg.muted" disabled={!isAvailable} variant="ghost" onClick={openPicker}>
<Icon as={UploadIcon} boxSize="3.5" />
</IconButton>
</Tooltip>
</>
);
};