import { Box, VStack, HStack, SpanBox } from '../../elements/LayoutPrimitives'
import { StyledText } from '../../elements/StyledText'
import { LabelChip } from '../../elements/LabelChip'
import type { LinkedItemCardProps } from './CardTypes'
import { CoverImage } from '../../elements/CoverImage'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { useState } from 'react'
import { DotsThree } from 'phosphor-react'
dayjs.extend(relativeTime)
//Styles
const ellipsisText = {
overflow: 'hidden',
display: '-webkit-box',
WebkitLineClamp: 1,
WebkitBoxOrient: 'vertical',
margin: 'auto 0',
pr: '10px',
}
const cardTitleStyle = {
...ellipsisText,
width: '100%',
fontSize: '14px',
fontWeight: '600',
textAlign: 'left',
}
// Props
type CardTitleProps = {
title: string
}
// Functions
function CardTitle(props: CardTitleProps): JSX.Element {
return (
{props.title}
)
}
type ProgressBarProps = {
fillPercentage: number
fillColor: string
backgroundColor: string
borderRadius: string
}
export function ProgressBar(props: ProgressBarProps): JSX.Element {
return (
)
}
const timeAgo = (date: string | undefined): string => {
if (!date) {
return ''
}
return dayjs(date).fromNow()
}
const shouldHideUrl = (url: string): boolean => {
try {
const origin = new URL(url).origin
const hideHosts = ['https://storage.googleapis.com', 'https://omnivore.app']
if (hideHosts.indexOf(origin) != -1) {
return true
}
} catch {
console.log('invalid url item', url)
}
return false
}
const siteName = (originalArticleUrl: string, itemUrl: string): string => {
if (shouldHideUrl(originalArticleUrl)) {
return ''
}
try {
return new URL(originalArticleUrl).hostname.replace(/^www\./, '')
} catch {}
try {
return new URL(itemUrl).hostname.replace(/^www\./, '')
} catch {}
return ''
}
// Component
export function LibraryGridCard(props: LinkedItemCardProps): JSX.Element {
const [isHovered, setIsHovered] = useState(false)
const originText =
props.item.siteName ||
siteName(props.item.originalArticleUrl, props.item.url)
return (
{
setIsHovered(true)
}}
onMouseLeave={() => {
setIsHovered(false)
}}
>
{timeAgo(props.item.savedAt)}
{isHovered ? (
) : (
15 min read
)}
{props.item.title}
{props.item.description}
{props.item.author}
{props.item.author && originText && ' | '}
{originText}
{props.item.labels?.map(({ name, color }, index) => (
))}
{props.item.image && (
{
;(e.target as HTMLElement).style.display = 'none'
}}
/>
)}
)
}
// // Component
// export function LibraryGridCard(props: LinkedItemCardProps): JSX.Element {
// return (
// {
// props.handleAction('showDetail')
// }}
// >
//
//
//
// {
// // This is here to prevent menu click events from bubbling
// // up and causing us to "click" on the link item.
// e.stopPropagation()
// }}
// >
//
// }
// actionHandler={props.handleAction}
// />
//
//
//
//
// {props.item.author && (
// {removeHTMLTags(props.item.author)}
// )}
// {props.originText && (
// <>
//
//
// {props.originText}
//
// >
// )}
//
//
//
//
//
// {props.item.description}
//
//
//
// {props.item.labels?.map(({ name, color }, index) => (
//
// ))}
//
//
//
//
// )
// }