cleanup
This commit is contained in:
@@ -13,7 +13,7 @@ interface DocumentLike {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface PreviewEntry {
|
||||
interface DocumentLink {
|
||||
url?: string;
|
||||
contentType?: string;
|
||||
filename?: string;
|
||||
@@ -36,7 +36,7 @@ type LayoutMode = 'split' | 'stacked' | (string & {});
|
||||
|
||||
interface DocumentViewerLayoutProps {
|
||||
document?: DocumentLike | null;
|
||||
previewEntry?: PreviewEntry | null;
|
||||
documentLink?: DocumentLink | null;
|
||||
summaryProps?: Record<string, unknown>;
|
||||
metadataPayload?: unknown;
|
||||
contentTabConfig?: ContentTabConfig | null;
|
||||
@@ -81,7 +81,7 @@ const getFileExtension = (filename?: string | null) => {
|
||||
|
||||
const DocumentViewerLayout = ({
|
||||
document,
|
||||
previewEntry,
|
||||
documentLink,
|
||||
summaryProps = {},
|
||||
metadataPayload,
|
||||
contentTabConfig,
|
||||
@@ -96,15 +96,15 @@ const DocumentViewerLayout = ({
|
||||
const viewportRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const previewContent = useMemo(() => {
|
||||
if (!document || !previewEntry?.url) {
|
||||
if (!document || !documentLink?.url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalizedContentType = (previewEntry.contentType
|
||||
const normalizedContentType = (documentLink.contentType
|
||||
|| document.content_type
|
||||
|| '')
|
||||
.toLowerCase();
|
||||
const normalizedFilename = previewEntry.filename
|
||||
const normalizedFilename = documentLink.filename
|
||||
|| document.filename
|
||||
|| document.original_name
|
||||
|| '';
|
||||
@@ -123,7 +123,7 @@ const DocumentViewerLayout = ({
|
||||
if (isImage) {
|
||||
return (
|
||||
<img
|
||||
src={previewEntry.url}
|
||||
src={documentLink.url}
|
||||
alt={`Preview of ${document.title}`}
|
||||
className="document-viewer__object document-viewer__object--image"
|
||||
draggable={false}
|
||||
@@ -137,7 +137,7 @@ const DocumentViewerLayout = ({
|
||||
|| document.original_name;
|
||||
return (
|
||||
<PdfViewer
|
||||
src={previewEntry.url}
|
||||
src={documentLink.url}
|
||||
title={documentTitle ? `Preview of ${documentTitle}` : undefined}
|
||||
viewportRef={viewportRef}
|
||||
/>
|
||||
@@ -150,7 +150,7 @@ const DocumentViewerLayout = ({
|
||||
className="document-viewer__object document-viewer__object--audio"
|
||||
controls
|
||||
preload="metadata"
|
||||
src={previewEntry.url}
|
||||
src={documentLink.url}
|
||||
aria-label={`Audio preview of ${mediaLabel}`}
|
||||
>
|
||||
</audio>
|
||||
@@ -163,15 +163,15 @@ const DocumentViewerLayout = ({
|
||||
className="document-viewer__object document-viewer__object--video"
|
||||
controls
|
||||
preload="metadata"
|
||||
src={previewEntry.url}
|
||||
src={documentLink.url}
|
||||
aria-label={`Video preview of ${mediaLabel}`}
|
||||
>
|
||||
</video>
|
||||
);
|
||||
}
|
||||
|
||||
const displayContentType = document.content_type || previewEntry.contentType || 'this file type';
|
||||
const displayFilename = previewEntry.filename
|
||||
const displayContentType = document.content_type || documentLink.contentType || 'this file type';
|
||||
const displayFilename = documentLink.filename
|
||||
|| document.filename
|
||||
|| document.original_name
|
||||
|| 'download';
|
||||
@@ -184,7 +184,7 @@ const DocumentViewerLayout = ({
|
||||
<div className="document-viewer__unsupported-filename">{displayFilename}</div>
|
||||
<a
|
||||
className="button-link document-viewer__unsupported-download"
|
||||
href={previewEntry.url}
|
||||
href={documentLink.url}
|
||||
download={displayFilename}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
@@ -194,17 +194,17 @@ const DocumentViewerLayout = ({
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}, [document, previewEntry, viewportRef]);
|
||||
}, [document, documentLink, viewportRef]);
|
||||
|
||||
const renderViewportPane = useCallback(() => (
|
||||
<div className="document-viewer__viewport" ref={viewportRef}>
|
||||
{!previewEntry?.url ? (
|
||||
{!documentLink?.url ? (
|
||||
<div className="document-viewer__message">{previewLoadingMessage}</div>
|
||||
) : (
|
||||
previewContent
|
||||
)}
|
||||
</div>
|
||||
), [previewContent, previewEntry?.url, previewLoadingMessage, viewportRef]);
|
||||
), [previewContent, documentLink?.url, previewLoadingMessage, viewportRef]);
|
||||
|
||||
const viewportPane = renderViewportPane();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user