diff --git a/src/app/molecules/media/Media.jsx b/src/app/molecules/media/Media.jsx index 9490e6c7..a9482470 100644 --- a/src/app/molecules/media/Media.jsx +++ b/src/app/molecules/media/Media.jsx @@ -416,31 +416,79 @@ function Embed({ link }) { return ; } - // TODO: url preview - // const [urlPreviewInfo, setUrlPreviewInfo] = useState(null); - // const mx = initMatrix.matrixClient; + const [urlPreviewInfo, setUrlPreviewInfo] = useState({}); + const mx = initMatrix.matrixClient; - // useEffect(() => { - // let unmounted = false; + useEffect(() => { + let unmounted = false; - // async function getThumbnail() { - // const info = await mx.getUrlPreview(link, 0); - // console.log('DEBUG', info); - // if (unmounted) return; + async function getUrlPreview() { + const info = await mx.getUrlPreview(link, 0); + if (unmounted) return; + setUrlPreviewInfo(info); + } - // setUrlPreviewInfo(info); - // } + getUrlPreview(); - // getThumbnail(); + return () => { + unmounted = true; + }; + }); - // return () => { - // unmounted = true; - // }; - // }); + if (urlPreviewInfo !== undefined) { + // Image only embed + if (urlPreviewInfo['og:image'] != null && urlPreviewInfo['og:image:width'] != null && urlPreviewInfo['og:image:height'] != null && urlPreviewInfo['og:title'] == null && urlPreviewInfo['og:description'] == null) { + return ( +
+ +
+ ); + } - // if (urlPreviewInfo !== null) { - // return
url preview here!/div>; - // } + let embedTitle; + + if (urlPreviewInfo['og:site_name'] != null && urlPreviewInfo['og:title'] != null) { + embedTitle = `${urlPreviewInfo['og:site_name']} - ${urlPreviewInfo['og:title']}`; + } else { + embedTitle = urlPreviewInfo['og:title'] || urlPreviewInfo['og:site_name']; + } + + return ( +
+
+
+ {(embedTitle != null) && ( + + {embedTitle} + + )} + + {(urlPreviewInfo['og:description'] != null) && ( + + {urlPreviewInfo['og:description']} + + )} +
+ + {urlPreviewInfo['og:image'] != null && urlPreviewInfo['og:image:width'] != null && urlPreviewInfo['og:image:height'] != null && ( + + )} +
+
+ ); + } return null; } diff --git a/src/app/molecules/media/Media.scss b/src/app/molecules/media/Media.scss index 8d98c428..4bd1d894 100644 --- a/src/app/molecules/media/Media.scss +++ b/src/app/molecules/media/Media.scss @@ -88,3 +88,14 @@ width: 100%; } } + +.embed-container { + color: var(--tc-surface-low); + background-color: var(--bg-surface-hover); + border-radius: calc(var(--bo-radius) / 2); + padding: 15px; + + .embed-text { + margin-bottom: 5px; + } +} \ No newline at end of file