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, DotsThreeVertical } from 'phosphor-react'
import Link from 'next/link'
import { CardMenu } from '../CardMenu'
import { Dropdown, DropdownOption } from '../../elements/DropdownElements'
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)}
{` `}
{props.item.wordsCount ?? 0 > 0
? ` • ${Math.max(
1,
Math.round((props.item.wordsCount ?? 0) / 235)
)} min read`
: null}
}
/>
{props.item.title}
test{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'
}}
/>
)}
)
}