omnivore/packages/web/components/patterns/LibraryCards/LinkedItemCard.tsx

31 lines
1 KiB
TypeScript
Raw Normal View History

import { GridLinkedItemCard } from './GridLinkedItemCard'
import { ListLinkedItemCard } from './ListLinkedItemCard'
import type { LinkedItemCardProps } from './CardTypes'
2022-05-03 19:09:32 +00:00
import { HighlightItemCard } from './HighlightItemCard'
import { PageType } from '../../../lib/networking/fragments/articleFragment'
const siteName = (originalArticleUrl: string, itemUrl: string): string => {
try {
2022-05-12 02:32:35 +00:00
return new URL(originalArticleUrl).hostname.replace(/^www\./, '')
} catch {}
try {
2022-05-12 02:32:35 +00:00
return new URL(itemUrl).hostname.replace(/^www\./, '')
} catch {}
return ''
}
export function LinkedItemCard(props: LinkedItemCardProps): JSX.Element {
2022-05-12 02:32:10 +00:00
const originText =
props.item.siteName ||
siteName(props.item.originalArticleUrl, props.item.url)
2022-05-03 19:09:32 +00:00
if (props.item.pageType === PageType.HIGHLIGHTS) {
return <HighlightItemCard {...props} />
}
if (props.layout == 'LIST_LAYOUT') {
return <ListLinkedItemCard {...props} originText={originText} />
} else {
return <GridLinkedItemCard {...props} originText={originText} />
}
}