import type { FC } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine, RiLoader2Line, } from '@remixicon/react' import cn from '@/utils/classnames' import { RefreshCcw01 } from '@/app/components/base/icons/src/vender/line/arrows' import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' import Tooltip from '@/app/components/base/tooltip' import type { ImageFile } from '@/types/app' import { TransferMethod } from '@/types/app' import ImagePreview from '@/app/components/base/image-uploader/image-preview' type ImageListProps = { list: ImageFile[] readonly?: boolean onRemove?: (imageFileId: string) => void onReUpload?: (imageFileId: string) => void onImageLinkLoadSuccess?: (imageFileId: string) => void onImageLinkLoadError?: (imageFileId: string) => void } const ImageList: FC = ({ list, readonly, onRemove, onReUpload, onImageLinkLoadSuccess, onImageLinkLoadError, }) => { const { t } = useTranslation() const [imagePreviewUrl, setImagePreviewUrl] = useState('') const handleImageLinkLoadSuccess = (item: ImageFile) => { if ( item.type === TransferMethod.remote_url && onImageLinkLoadSuccess && item.progress !== -1 ) onImageLinkLoadSuccess(item._id) } const handleImageLinkLoadError = (item: ImageFile) => { if (item.type === TransferMethod.remote_url && onImageLinkLoadError) onImageLinkLoadError(item._id) } return (
{list.map(item => (
{item.type === TransferMethod.local_file && item.progress !== 100 && ( <>
-1 ? `${item.progress}%` : 0 }} > {item.progress === -1 && ( onReUpload && onReUpload(item._id)} /> )}
{item.progress > -1 && ( {item.progress}% )} )} {item.type === TransferMethod.remote_url && item.progress !== 100 && (
{item.progress > -1 && ( )} {item.progress === -1 && ( )}
)} {item.file?.name} handleImageLinkLoadSuccess(item)} onError={() => handleImageLinkLoadError(item)} src={ item.type === TransferMethod.remote_url ? item.url : item.base64Url } onClick={() => item.progress === 100 && setImagePreviewUrl( (item.type === TransferMethod.remote_url ? item.url : item.base64Url) as string, ) } /> {!readonly && ( )}
))} {imagePreviewUrl && ( setImagePreviewUrl('')} title='' /> )}
) } export default ImageList