2021-04-14 18:56:29 -05:00
|
|
|
import Link from 'next/link'
|
2021-04-13 19:57:32 -05:00
|
|
|
import styles from './item.module.css'
|
2021-04-22 17:14:32 -05:00
|
|
|
import UpVote from './upvote'
|
2023-07-09 11:15:46 -05:00
|
|
|
import { useRef, useState } from 'react'
|
2021-09-02 13:11:27 -05:00
|
|
|
import { NOFOLLOW_LIMIT } from '../lib/constants'
|
2022-01-10 12:53:26 -06:00
|
|
|
import Pin from '../svgs/pushpin-fill.svg'
|
2022-02-03 16:01:42 -06:00
|
|
|
import reactStringReplace from 'react-string-replace'
|
2022-07-30 08:25:46 -05:00
|
|
|
import PollIcon from '../svgs/bar-chart-horizontal-fill.svg'
|
2023-01-26 10:11:55 -06:00
|
|
|
import BountyIcon from '../svgs/bounty-bag.svg'
|
|
|
|
import ActionTooltip from './action-tooltip'
|
2022-09-21 14:57:36 -05:00
|
|
|
import Flag from '../svgs/flag-fill.svg'
|
2022-10-25 16:35:32 -05:00
|
|
|
import { abbrNum } from '../lib/format'
|
2023-02-16 23:23:59 +01:00
|
|
|
import ItemInfo from './item-info'
|
2022-02-03 16:01:42 -06:00
|
|
|
|
2022-07-21 17:55:05 -05:00
|
|
|
export function SearchTitle ({ title }) {
|
2022-02-03 16:29:48 -06:00
|
|
|
return reactStringReplace(title, /:high\[([^\]]+)\]/g, (match, i) => {
|
2022-02-03 16:01:42 -06:00
|
|
|
return <mark key={`mark-${match}`}>{match}</mark>
|
|
|
|
})
|
|
|
|
}
|
2021-04-13 19:57:32 -05:00
|
|
|
|
2023-05-11 14:34:42 -05:00
|
|
|
export default function Item ({ item, rank, belowTitle, right, full, children }) {
|
2021-09-15 18:42:44 -05:00
|
|
|
const titleRef = useRef()
|
2023-07-09 11:15:46 -05:00
|
|
|
const [pendingSats, setPendingSats] = useState(0)
|
2021-09-15 18:42:44 -05:00
|
|
|
|
2021-04-13 19:57:32 -05:00
|
|
|
return (
|
2021-04-14 18:56:29 -05:00
|
|
|
<>
|
2021-04-22 17:14:32 -05:00
|
|
|
{rank
|
|
|
|
? (
|
|
|
|
<div className={styles.rank}>
|
|
|
|
{rank}
|
|
|
|
</div>)
|
|
|
|
: <div />}
|
2021-04-14 18:56:29 -05:00
|
|
|
<div className={styles.item}>
|
2022-09-21 14:57:36 -05:00
|
|
|
{item.position
|
|
|
|
? <Pin width={24} height={24} className={styles.pin} />
|
2023-07-09 11:15:46 -05:00
|
|
|
: item.meDontLike ? <Flag width={24} height={24} className={`${styles.dontLike}`} /> : <UpVote item={item} className={styles.upvote} pendingSats={pendingSats} setPendingSats={setPendingSats} />}
|
2021-04-14 18:56:29 -05:00
|
|
|
<div className={styles.hunk}>
|
2023-05-01 15:58:30 -05:00
|
|
|
<div className={`${styles.main} flex-wrap`}>
|
2021-04-14 18:56:29 -05:00
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
2022-02-03 16:01:42 -06:00
|
|
|
<a ref={titleRef} className={`${styles.title} text-reset mr-2`}>
|
|
|
|
{item.searchTitle ? <SearchTitle title={item.searchTitle} /> : item.title}
|
2022-07-30 08:25:46 -05:00
|
|
|
{item.pollCost && <span> <PollIcon className='fill-grey vertical-align-baseline' height={14} width={14} /></span>}
|
2023-01-26 10:11:55 -06:00
|
|
|
{item.bounty > 0 &&
|
|
|
|
<span>
|
2023-01-26 13:09:57 -06:00
|
|
|
<ActionTooltip notForm overlayText={`${abbrNum(item.bounty)} ${item.bountyPaidTo?.length ? 'sats paid' : 'sats bounty'}`}>
|
|
|
|
<BountyIcon className={`${styles.bountyIcon} ${item.bountyPaidTo?.length ? 'fill-success vertical-align-middle' : 'fill-grey vertical-align-middle'}`} height={16} width={16} />
|
2023-01-26 10:11:55 -06:00
|
|
|
</ActionTooltip>
|
|
|
|
</span>}
|
2022-02-03 16:01:42 -06:00
|
|
|
</a>
|
2021-04-14 18:56:29 -05:00
|
|
|
</Link>
|
2021-05-20 14:11:58 -05:00
|
|
|
{item.url &&
|
2021-12-06 15:27:14 -06:00
|
|
|
<>
|
|
|
|
{/* eslint-disable-next-line */}
|
|
|
|
<a
|
2023-05-01 15:58:30 -05:00
|
|
|
className={`${styles.link} py-half py-md-0`} target='_blank' href={item.url}
|
2021-12-06 15:27:14 -06:00
|
|
|
rel={item.sats + item.boost >= NOFOLLOW_LIMIT ? null : 'nofollow'}
|
|
|
|
>
|
|
|
|
{item.url.replace(/(^https?:|^)\/\//, '')}
|
|
|
|
</a>
|
|
|
|
</>}
|
2021-04-14 18:56:29 -05:00
|
|
|
</div>
|
2023-07-09 11:15:46 -05:00
|
|
|
<ItemInfo full={full} item={item} pendingSats={pendingSats} />
|
2023-02-16 23:23:59 +01:00
|
|
|
{belowTitle}
|
2021-04-13 19:57:32 -05:00
|
|
|
</div>
|
2023-02-16 23:23:59 +01:00
|
|
|
{right}
|
2021-04-13 19:57:32 -05:00
|
|
|
</div>
|
2021-04-14 18:56:29 -05:00
|
|
|
{children && (
|
|
|
|
<div className={styles.children}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2021-04-13 19:57:32 -05:00
|
|
|
)
|
|
|
|
}
|
2021-04-22 17:14:32 -05:00
|
|
|
|
2021-04-26 19:55:48 -05:00
|
|
|
export function ItemSkeleton ({ rank, children }) {
|
2021-04-22 17:14:32 -05:00
|
|
|
return (
|
|
|
|
<>
|
2022-01-27 13:18:48 -06:00
|
|
|
{rank
|
|
|
|
? (
|
|
|
|
<div className={styles.rank}>
|
|
|
|
{rank}
|
|
|
|
</div>)
|
|
|
|
: <div />}
|
2021-04-22 17:14:32 -05:00
|
|
|
<div className={`${styles.item} ${styles.skeleton}`}>
|
2021-04-28 14:30:14 -05:00
|
|
|
<UpVote className={styles.upvote} />
|
2021-04-22 17:14:32 -05:00
|
|
|
<div className={styles.hunk}>
|
|
|
|
<div className={`${styles.main} flex-wrap flex-md-nowrap`}>
|
|
|
|
<span className={`${styles.title} clouds text-reset flex-md-fill flex-md-shrink-0 mr-2`} />
|
|
|
|
<span className={`${styles.link} clouds`} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.other}>
|
2021-04-28 17:52:03 -05:00
|
|
|
<span className={`${styles.otherItem} clouds`} />
|
2021-04-22 17:14:32 -05:00
|
|
|
<span className={`${styles.otherItem} clouds`} />
|
|
|
|
<span className={`${styles.otherItem} ${styles.otherItemLonger} clouds`} />
|
|
|
|
<span className={`${styles.otherItem} ${styles.otherItemLonger} clouds`} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-26 19:55:48 -05:00
|
|
|
{children && (
|
|
|
|
<div className={styles.children}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
2021-04-22 17:14:32 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|