Middle click to open the preview card thumbnail in a new tab

This commit is contained in:
piko-piko committed 2026-03-14 12:22:31 +01:00
1 parent f008ca80ef
commit 93c51ce6cc
1 file changed
+20 -1
@@ -14,9 +14,17 @@ import { UrlPreview, UrlPreviewContent, UrlPreviewDescription } from './UrlPrevi
import { AudioContent, ImageContent, VideoContent } from '../message';
import { Image, MediaControl, Video } from '../media';
import { ImageViewer } from '../image-viewer';
import { downloadMedia } from '$utils/matrix';
const linkStyles = { color: color.Success.Main };
const openMediaInNewTab = async (url: string | undefined) => {
if (!url) { console.warn("Attempted to open an empty url"); return}
const blob = await downloadMedia(url);
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, "_blank");
}
export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: string | null }>(
({ url, ts, mediaType, ...props }, ref) => {
const mx = useMatrixClient();
@@ -50,6 +58,17 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
'scale',
false
);
const handleAuxClick = (ev: React.MouseEvent) => {
if (!prev['og:image']) { console.warn("No image"); return; }
if (ev.button === 1) {
ev.preventDefault();
const useAuthentication = true;
const mxcUrl = mxcUrlToHttp(mx, prev['og:image'], useAuthentication);
if (!mxcUrl) { console.error("Error converting mxc:// url."); return; };
openMediaInNewTab(mxcUrl);
}
};
return (
<Box
@@ -128,6 +147,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
<ImageContent
style={{ width: '100%', height: '100%', position: 'absolute', inset: 0 }}
autoPlay
onAuxClick={handleAuxClick}
body={prev['og:title']}
url={prev['og:image']}
renderViewer={(p) => <ImageViewer {...p} />}
@@ -187,7 +207,6 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
</Box>
);
}
return (
<UrlPreview
{...props}