import Link from 'next/link' import styles from './item.module.css' import UpVote from './upvote' import { useRef, useState } from 'react' import { AD_USER_ID, NOFOLLOW_LIMIT } from '../lib/constants' import Pin from '../svgs/pushpin-fill.svg' import reactStringReplace from 'react-string-replace' import PollIcon from '../svgs/bar-chart-horizontal-fill.svg' import BountyIcon from '../svgs/bounty-bag.svg' import ActionTooltip from './action-tooltip' import Flag from '../svgs/flag-fill.svg' import ImageIcon from '../svgs/image-fill.svg' import { numWithUnits } from '../lib/format' import ItemInfo from './item-info' import { commentsViewedAt } from '../lib/new-comments' import { useRouter } from 'next/router' import { Badge } from 'react-bootstrap' import AdIcon from '../svgs/advertisement-fill.svg' export function SearchTitle ({ title }) { return reactStringReplace(title, /:high\[([^\]]+)\]/g, (match, i) => { return {match} }) } export default function Item ({ item, rank, belowTitle, right, full, children, siblingComments }) { const titleRef = useRef() const router = useRouter() const [pendingSats, setPendingSats] = useState(0) const image = item.url && item.url.startsWith(process.env.NEXT_PUBLIC_IMGPROXY_URL) return ( <> {rank ? (
{rank}
) :
}
{item.position ? : item.meDontLike ? : Number(item.user?.id) === AD_USER_ID ? : }
{ const viewedAt = commentsViewedAt(item) if (viewedAt) { e.preventDefault() router.push( `/items/${item.id}?commentsViewedAt=${viewedAt}`, `/items/${item.id}`) } }} ref={titleRef} className={`${styles.title} text-reset me-2`} > {item.searchTitle ? : item.title} {item.pollCost && } {item.bounty > 0 && } {image && } {item.url && !image && <> {/* eslint-disable-next-line */} = NOFOLLOW_LIMIT ? null : 'nofollow'} > {item.url.replace(/(^https?:|^)\/\//, '')} }
AD} /> {belowTitle}
{right}
{children && (
{children}
)} ) } export function ItemSkeleton ({ rank, children }) { return ( <> {rank ? (
{rank}
) :
}
{children && (
{children}
)} ) }