diff --git a/pkg/interface/src/stories/LinkBlockItem.stories.tsx b/pkg/interface/src/stories/LinkBlockItem.stories.tsx index 41faecfa8..b3178109d 100644 --- a/pkg/interface/src/stories/LinkBlockItem.stories.tsx +++ b/pkg/interface/src/stories/LinkBlockItem.stories.tsx @@ -4,6 +4,8 @@ import { withDesign } from 'storybook-addon-designs'; import { Col, Row } from '@tlon/indigo-react'; import { LinkBlockItem } from '~/views/apps/links/components/LinkBlockItem'; +import { createPost, GraphNode } from '@urbit/api'; +import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap'; export default { title: 'Collections/BlockItem', @@ -11,11 +13,37 @@ export default { decorators: [withDesign] } as Meta; +const createLink = (text: string, url: string) => ({ + post: createPost('sampel-palnet', [{ text }, { url }]), + children: new BigIntOrderedMap() +}); + export const Image = () => ( - - - + + + ); @@ -29,8 +57,10 @@ Image.parameters = { export const Fallback = () => ( - - + + ); @@ -45,8 +75,10 @@ Fallback.parameters = { export const Audio = () => ( ); @@ -62,8 +94,17 @@ Audio.parameters = { export const Youtube = () => ( + ); diff --git a/pkg/interface/src/views/apps/links/components/LinkBlockItem.tsx b/pkg/interface/src/views/apps/links/components/LinkBlockItem.tsx index 969a52ffa..17ebad21f 100644 --- a/pkg/interface/src/views/apps/links/components/LinkBlockItem.tsx +++ b/pkg/interface/src/views/apps/links/components/LinkBlockItem.tsx @@ -1,50 +1,68 @@ import React from 'react'; import { - BaseImage, Icon, Center, Row, Text, - BoxProps, Col, Box, + CenterProps } from '@tlon/indigo-react'; +import { hasProvider } from 'oembed-parser'; import { AUDIO_REGEX, IMAGE_REGEX } from '~/views/components/RemoteContent'; import { AudioPlayer } from '~/views/components/AudioPlayer'; import { useHistory } from 'react-router'; import { useHovering } from '~/logic/lib/util'; import Author from '~/views/components/Author'; -import { GraphNode, Post, TextContent, UrlContent } from '@urbit/api'; +import { + GraphNode, + ReferenceContent, + TextContent, + UrlContent +} from '@urbit/api'; +import { + RemoteContentEmbedFallback, + RemoteContentImageEmbed, + RemoteContentOembed, + RemoteContentPermalinkEmbed +} from '~/views/components/RemoteContent/embed'; +import { PermalinkEmbed } from '../../permalinks/embed'; +import { referenceToPermalink } from '~/logic/lib/permalinks'; +import GlobalApi from '~/logic/api/global'; export interface LinkBlockItemProps { node: GraphNode; - size?: BoxProps['height']; - m?: BoxProps['m']; - border?: BoxProps['border']; + size?: CenterProps['height']; + border?: CenterProps['border']; summary?: boolean; + api: GlobalApi; } -function getYoutubeId(str: string): string | null { - const youtube = str.match(/youtube\.com.*(\?v=|\/embed\/)(.{11})/); - if (!youtube) { - return null; - } - return youtube.pop(); -} - -export function LinkBlockItem(props: LinkBlockItemProps) { - const { node, summary, size = '256px', m, border = 1 } = props; +export function LinkBlockItem(props: LinkBlockItemProps & CenterProps) { + const { api, node, summary, size, m, border = 1, ...rest } = props; const { post, children } = node; const { contents, index, author } = post; - const [{ text: title }, { url }] = contents as [TextContent, UrlContent]; + + const [{ text: title }, ...content] = contents as [ + TextContent, + UrlContent | ReferenceContent + ]; + let url = ''; + if ('url' in content?.[0]) { + url = content[0].url; + } + + const isReference = 'reference' in content[0]; const isImage = IMAGE_REGEX.test(url); const isAudio = AUDIO_REGEX.test(url); - const youtube = getYoutubeId(url); + + const isOembed = hasProvider(url); const history = useHistory(); const { hovering, bind } = useHovering(); const onClick = () => { - history.push(`${history.location.pathname}/index${index}`); + const { pathname, search } = history.location; + history.push(`${pathname}/index${index}${search}`); }; return (
- {isImage ? ( - + {isReference ? ( + summary ? ( + + ) : ( + + ) + ) : isImage ? ( + ) : isAudio ? ( - ) : youtube ? ( - + ) : isOembed ? ( + ) : ( - - - - {url} - - + )}