1 import type { ReactNode, Ref } from 'react';
2 import { forwardRef, useMemo } from 'react';
4 import { c } from 'ttag';
6 import type { ModalStateProps } from '@proton/components';
7 import { FilePreview } from '@proton/components';
8 import { Portal } from '@proton/components/components/portal';
10 import { useDriveSharingFlags, useFileView } from '../../store';
11 import { getSharedStatus } from '../../utils/share';
12 import { SignatureAlertBody } from '../SignatureAlert';
13 import SignatureIcon from '../SignatureIcon';
19 date?: Date | string | number;
20 onDetails?: () => void;
21 onRestore?: () => void;
24 navigationControls?: ReactNode;
27 const PortalPreview = (
39 }: Props & ModalStateProps,
40 ref: Ref<HTMLDivElement>
42 const { contents, contentsMimeType, link, error, isLinkLoading, isContentLoading, downloadFile } = useFileView(
48 const { isSharingInviteAvailable } = useDriveSharingFlags();
50 const signatureStatus = useMemo(() => {
58 signatureIssues={link.signatureIssues}
59 isAnonymous={!link.activeRevision?.signatureAddress && !link.signatureAddress}
60 className="ml-2 color-danger"
65 const signatureConfirmation = useMemo(() => {
66 if (!link?.signatureIssues?.blocks) {
72 signatureIssues={link.signatureIssues}
73 signatureAddress={link.activeRevision?.signatureAddress || link.signatureAddress}
80 if (!modalProps.open) {
84 const showCachedThumbnail = revisionId === link?.activeRevision?.id;
88 <div className={className}>
90 imgThumbnailUrl={showCachedThumbnail ? link?.cachedThumbnailUrl : undefined}
91 isMetaLoading={isLinkLoading}
92 isLoading={isContentLoading}
93 error={error ? error.message || error.toString?.() || c('Info').t`Unknown error` : undefined}
95 mimeType={contentsMimeType}
96 isSharingInviteAvailable={isSharingInviteAvailable}
97 sharedStatus={getSharedStatus(link)}
101 modalProps.onClose();
105 onDownload={downloadFile}
106 onDetails={onDetails}
107 onRestore={onRestore}
110 navigationControls={navigationControls}
111 signatureStatus={signatureStatus}
112 signatureConfirmation={signatureConfirmation}
119 export default forwardRef(PortalPreview);