import Link from 'next/link' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' import Badge from 'react-bootstrap/Badge' import Dropdown from 'react-bootstrap/Dropdown' 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 SubscribeDropdownItem from './subscribe' import { CopyLinkDropdownItem } from './share' export default function ItemInfo ({ item, pendingSats, full, 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) const [meTotalSats, setMeTotalSats] = useState(0) useEffect(() => { if (!full) { setHasNewComments(newComments(item)) } }, [item]) useEffect(() => { if (item) setMeTotalSats(item.meSats + item.meAnonSats + pendingSats) }, [item?.meSats, item?.meAnonSats, pendingSats]) return (
{!item.position && <> {abbrNum(item.sats + pendingSats)} 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.subName && {' '}{item.subName} } {(item.outlawed && !item.mine && {' '}outlawed ) || (item.freebie && {' '}freebie )} {canEdit && !item.deletedAt && <> \ onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)} > {editText || 'edit'} { setCanEdit(false) }} /> } {me && } {me && item.user.id !== me.id && } {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} ) }