RemoteContent: fix graphcontent embedding

This commit is contained in:
Liam Fitzgerald 2021-06-22 04:26:39 +10:00
parent 13ebd15609
commit 3d4b4901bb
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
5 changed files with 20 additions and 31 deletions

View File

@ -38,3 +38,9 @@ Twitter.args = {
// massive test flake
unfold: false
};
export const Fallback = Template.bind({});
Fallback.args = {
url: 'https://www.are.na/edouard-urcades/edouard'
};

View File

@ -92,7 +92,7 @@ export function LinkBlockItem(props: LinkBlockItemProps & CenterProps) {
) : isAudio ? (
<AudioPlayer title={title} url={url} />
) : isOembed ? (
<RemoteContentOembed renderUrl url={url} thumbnail={summary} />
<RemoteContentOembed tall={!summary} renderUrl url={url} thumbnail={summary} />
) : (
<RemoteContentEmbedFallback url={url} />
)}

View File

@ -22,11 +22,11 @@ import { TruncatedText } from '~/views/components/TruncatedText';
import { getModuleIcon, useHovering } from '~/logic/lib/util';
import { IconRef, PropFunc } from '~/types';
import { system } from 'styled-system';
import { extract } from 'oembed-parser';
import { Association, GraphConfig, ReferenceContent } from '@urbit/api';
import { Link } from 'react-router-dom';
import { referenceToPermalink } from '~/logic/lib/permalinks';
import useMetadataState from '~/logic/state/metadata';
import { RemoteContentWrapper } from './wrapper';
interface RemoteContentEmbedProps {
url: string;
@ -235,9 +235,7 @@ export const RemoteContentOembed = React.forwardRef<
useEffect(() => {
const getEmbed = async () => {
try {
// const { width, height } = ourRef.current.getBoundingClientRect();
const oembed = await extract(url);
const oembed = await (await fetch(`https://noembed.com/embed?url=${encodeURIComponent(url)}`)).json();
setEmbed(oembed);
} catch (e) {
console.error(e);
@ -251,11 +249,8 @@ export const RemoteContentOembed = React.forwardRef<
if (!renderUrl && !embed) {
return null;
}
if (!embed) {
return <RemoteContentEmbedFallback url={url} />;
}
return (
const detail = (
<Col
ref={ourRef}
mb={2}
@ -266,17 +261,6 @@ export const RemoteContentOembed = React.forwardRef<
alignItems="center"
{...rest}
>
<TruncatedText
display={
renderUrl && embed?.title && embed.title !== url
? 'inline-block'
: 'none'
}
fontWeight="bold"
width="100%"
>
{embed?.title}
</TruncatedText>
{thumbnail && embed?.['thumbnail_url'] ? (
<BaseImage
height="100%"
@ -285,13 +269,19 @@ export const RemoteContentOembed = React.forwardRef<
/>
) : !thumbnail && embed?.html ? (
<EmbedContainer markup={embed.html}>
<EmbedBox dangerouslySetInnerHTML={{ __html: embed.html }}></EmbedBox>
<EmbedBox ref={ref} dangerouslySetInnerHTML={{ __html: embed.html }}></EmbedBox>
</EmbedContainer>
) : renderUrl ? (
<RemoteContentEmbedFallback url={url} />
) : null}
</Col>
);
return (
<RemoteContentWrapper url={url} detail={detail}>
<TruncatedText>{embed?.title ?? url}</TruncatedText>
</RemoteContentWrapper>
);
});
export function RemoteContentEmbedFallback(props: RemoteContentEmbedProps) {

View File

@ -58,7 +58,7 @@ export function RemoteContent(props: RemoteContentProps) {
const wrapperProps = {
url,
tall,
embedOnly: !renderUrl
embedOnly: (!renderUrl || tall)
};
if (isImage && remoteContentPolicy.imageShown) {
@ -89,14 +89,7 @@ export function RemoteContent(props: RemoteContentProps) {
);
} else if (isOembed && remoteContentPolicy.oembedShown) {
return (
<RemoteContentWrapper
{...wrapperProps}
detail={(
<RemoteContentOembed ref={embedRef} url={url} renderUrl={renderUrl} />
)}
>
<TruncatedText {...textProps}>{url}</TruncatedText>
</RemoteContentWrapper>
<RemoteContentOembed ref={embedRef} url={url} renderUrl={renderUrl} />
);
} else if(renderUrl) {
return (

View File

@ -72,7 +72,7 @@ export function RemoteContentWrapper(props: RemoteContentWrapperProps) {
{children}
</BaseAnchor>
</Row>
{detail}
{unfold ? detail : null}
</Box>
);
}