import Link from 'next/link' import styles from './item.module.css' import { timeSince } from '../lib/time' import UpVote from './upvote' import { useMe } from './me' import { useEffect, useRef, useState } from 'react' import Countdown from './countdown' import { NOFOLLOW_LIMIT } from '../lib/constants' export default function Item ({ item, rank, children }) { const me = useMe() const mine = me?.id === item.user.id const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000 const [canEdit, setCanEdit] = useState(mine && (Date.now() < editThreshold)) const [wrap, setWrap] = useState(false) const titleRef = useRef() useEffect(() => { setWrap( parseInt(window.getComputedStyle(titleRef.current).lineHeight) < titleRef.current.clientHeight) }, []) return ( <> {rank ? (
{rank}
) :
}
{item.title} {item.url && = NOFOLLOW_LIMIT ? null : 'nofollow'} > {item.url.replace(/(^https?:|^)\/\//, '')} }
{item.sats} sats \ {item.boost > 0 && <> {item.boost} boost \ } {item.tips > 0 && <> {item.tips} tipped \ } {item.ncomments} comments \ @{item.user.name} {timeSince(new Date(item.createdAt))} {canEdit && <> \ edit { setCanEdit(false) }} /> }
{children && (
{children}
)} ) } export function ItemSkeleton ({ rank, children }) { return ( <> {rank &&
{rank}
}
{children && (
{children}
)} ) }