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, numWithUnits } from '../lib/format' import { newComments, commentsViewedAt } from '../lib/new-comments' import { timeSince } from '../lib/time' import { DeleteDropdownItem } from './delete' import styles from './item.module.css' import { useMe } from './me' import DontLikeThisDropdownItem from './dont-link-this' import BookmarkDropdownItem from './bookmark' import SubscribeDropdownItem from './subscribe' import { CopyLinkDropdownItem } from './share' import Hat from './hat' import { AD_USER_ID } from '../lib/constants' import ActionDropdown from './action-dropdown' import MuteDropdownItem from './mute' import { DropdownItemUpVote } from './upvote' export default function ItemInfo ({ item, pendingSats, full, commentsText = 'comments', commentTextSingular = 'comment', className, embellishUser, extraInfo, onEdit, editText, onQuoteReply, nofollow, extraBadges }) { 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 || 0) + (item.meAnonSats || 0) + (pendingSats || 0)) }, [item?.meSats, item?.meAnonSats, pendingSats]) return (
{!item.position && !(!item.parentId && Number(item.user?.id) === AD_USER_ID) && <> {numWithUnits(item.sats + pendingSats)} \ } {item.boost > 0 && <> {abbrNum(item.boost)} boost \ } { const viewedAt = commentsViewedAt(item) if (viewedAt) { e.preventDefault() router.push( `/items/${item.id}?commentsViewedAt=${viewedAt}`, `/items/${item.id}`) } }} title={numWithUnits(item.commentSats)} className='text-reset position-relative' > {numWithUnits(item.ncomments, { abbreviate: false, unitPlural: commentsText, unitSingular: commentTextSingular })} {hasNewComments && {' '} } \ @{item.user.name} {embellishUser} {timeSince(new Date(item.createdAt))} {item.prior && <> \ yesterday } {item.subName && {' '}{item.subName} } {(item.outlawed && !item.mine && {' '}outlawed ) || (item.freebie && !item.position && {' '}freebie )} {extraBadges} {canEdit && !item.deletedAt && <> \ onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)} > {editText || 'edit'} { setCanEdit(false) }} /> } {(item.parentId || item.text) && onQuoteReply && quote reply} {me && } {me && } {item.otsHash && opentimestamp } {me && !item.position && !item.mine && !item.deletedAt && (item.meDontLikeSats > meTotalSats ? : )} {me && item?.noteId && ( window.open(`https://nostr.com/${item.noteId}`, '_blank', 'noopener')}> nostr note )} {item.mine && !item.position && !item.deletedAt && !item.bio && } {me && !item.mine && <>
}
{extraInfo}
) }