Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions apps/web/src/components/files/AttachmentFilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,6 @@ function renderedToggleLabel(mode: "markdown" | "html" | "table", rendered: bool
return rendered ? "Show HTML source" : "Show rendered page";
}

// useAssetUrlRefresh keys its callback on these objects, so they must stay cached.
function useAttachmentResources(
attachmentId: string | undefined,
fileName: string,
mimeType: string,
) {
"use memo";
const resource = attachmentId
? {
_tag: "attachment" as const,
attachmentId,
fileName,
mimeType,
disposition: "inline" as const,
}
: null;
const downloadResource = resource ? { ...resource, disposition: "attachment" as const } : null;
return { resource, downloadResource };
}

export function AttachmentFilePreview(props: {
name: string;
mimeType: string;
Expand All @@ -86,11 +66,17 @@ export function AttachmentFilePreview(props: {
kind === "markdown" ? "markdown" : kind === "html" ? "html" : delimiter ? "table" : null;
const attachmentId = props.asset?.attachmentId;
const { copyToClipboard, isCopied } = useCopyToClipboard({ target: props.name });
const { resource, downloadResource } = useAttachmentResources(
attachmentId,
props.name,
props.mimeType,
);
// useAssetUrlRefresh keys its callback on these objects, so they must stay cached.
const resource = attachmentId
? {
_tag: "attachment" as const,
attachmentId,
fileName: props.name,
mimeType: props.mimeType,
disposition: "inline" as const,
}
: null;
const downloadResource = resource ? { ...resource, disposition: "attachment" as const } : null;
const refresh = useAssetUrlRefresh(
props.file ? null : (props.asset?.environmentId ?? null),
props.file ? null : resource,
Expand Down
Loading