groups: avoid extra node in plain link URL

This still leaves an empty root node which does not take up visual
space though. A more comprehensive approach would be to filter out
plain URL links from the graph, eg from the function

```
t[1].children.map(c => {
    if (c?.children) {
      let links = [];
      c.children.filter(k => {
        if (k.type === 'link') {
          links.push({
            type: 'root',
            children: [
              {
                type: 'graph-url',
                url: k.url
              }
            ]
          })
        }
      })

      c.children.push(...links);
    }
  });
```
This commit is contained in:
André Fincato 2022-04-18 15:38:34 +02:00
parent dedacabb53
commit db6130146b
2 changed files with 28 additions and 21 deletions

View File

@ -1,3 +1,6 @@
import {
Box,
} from '@tlon/indigo-react';
import { hasProvider } from 'oembed-parser';
import React from 'react';
import useSettingsState from '~/logic/state/settings';
@ -64,36 +67,42 @@ export function RemoteContent(props: RemoteContentProps) {
embedOnly: !renderUrl || tall
};
const fallback = !renderUrl ? null : (
``
);
const fallback = null;
if (isImage && remoteContentPolicy.imageShown) {
return (
<RemoteContentWrapper {...wrapperProps} noOp={transcluded} replaced>
<RemoteContentImageEmbed url={url} />
</RemoteContentWrapper>
<Box mt={1} mb={2} flexShrink={0}>
<RemoteContentWrapper {...wrapperProps} noOp={transcluded} replaced>
<RemoteContentImageEmbed url={url} />
</RemoteContentWrapper>
</Box>
);
} else if (isAudio && remoteContentPolicy.audioShown) {
return (
<RemoteContentWrapper {...wrapperProps}>
<RemoteContentAudioEmbed url={url} />
</RemoteContentWrapper>
<Box mt={1} mb={2} flexShrink={0}>
<RemoteContentWrapper {...wrapperProps}>
<RemoteContentAudioEmbed url={url} />
</RemoteContentWrapper>
</Box>
);
} else if (isVideo && remoteContentPolicy.videoShown) {
return (
<RemoteContentWrapper
{...wrapperProps}
detail={<RemoteContentVideoEmbed url={url} />}
>
<TruncatedText>{url}</TruncatedText>
</RemoteContentWrapper>
<Box mt={1} mb={2} flexShrink={0}>
<RemoteContentWrapper
{...wrapperProps}
detail={<RemoteContentVideoEmbed url={url} />}
>
<TruncatedText>{url}</TruncatedText>
</RemoteContentWrapper>
</Box>
);
} else if (isOembed && remoteContentPolicy.oembedShown) {
return (
<AsyncFallback fallback={fallback}>
<RemoteContentOembed ref={embedRef} url={url} renderUrl={renderUrl} />
</AsyncFallback>
<Box mt={1} mb={2} flexShrink={0}>
<AsyncFallback fallback={fallback}>
<RemoteContentOembed ref={embedRef} url={url} renderUrl={renderUrl} />
</AsyncFallback>
</Box>
);
}
return fallback;

View File

@ -457,9 +457,7 @@ const renderers = {
</Box>
),
'graph-url': ({ url, tall }) => (
<Box mt={1} mb={2} flexShrink={0}>
<RemoteContent key={url} url={url} tall={tall} />
</Box>
<RemoteContent key={url} url={url} tall={tall} />
),
'graph-reference': ({ reference, transcluded }) => {
const { link } = referenceToPermalink({ reference });