import Link from 'next/link' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' import { Badge, Dropdown } from 'react-bootstrap' import Countdown from './countdown' import { abbrNum } from '../lib/format' import { newComments } from '../lib/new-comments' import { timeSince } from '../lib/time' import CowboyHat from './cowboy-hat' import { DeleteDropdownItem } from './delete' import styles from './item.module.css' import { useMe } from './me' import MoreIcon from '../svgs/more-fill.svg' import DontLikeThisDropdownItem from './dont-link-this' import BookmarkDropdownItem from './bookmark' import { CopyLinkDropdownItem } from './share' export default function ItemInfo ({ item, commentsText, className, embellishUser, extraInfo, onEdit, editText }) { const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000 const me = useMe() const router = useRouter() const [canEdit, setCanEdit] = useState(item.mine && (Date.now() < editThreshold)) const [hasNewComments, setHasNewComments] = useState(false) useEffect(() => { // if we are showing toc, then this is a full item setHasNewComments(newComments(item)) }, [item]) return (
{!item.position && <> {abbrNum(item.sats)} sats \ } {item.boost > 0 && <> {abbrNum(item.boost)} boost \ } {item.ncomments} {commentsText || 'comments'} {hasNewComments && <>{' '}new} \ @{item.user.name} {embellishUser} {timeSince(new Date(item.createdAt))} {item.prior && <> \ yesterday } {(item.outlawed && !item.mine && {' '}OUTLAWED ) || (item.freebie && !item.mine && {' '}FREEBIE )} {canEdit && !item.deletedAt && <> \ onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)} > {editText || 'edit'} { setCanEdit(false) }} /> } {me && } {item.otsHash && ots timestamp } {me && !item.meSats && !item.position && !item.meDontLike && !item.mine && !item.deletedAt && } {item.mine && !item.position && !item.deletedAt && } {extraInfo}
) } export function ItemDropdown ({ children }) { return ( {children} ) }