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-18 13:50:04 -05:00
|
|
|
import { timeSince } from '../lib/time'
|
2021-04-22 17:14:32 -05:00
|
|
|
import UpVote from './upvote'
|
2021-09-15 18:42:44 -05:00
|
|
|
import { useEffect, useRef, useState } from 'react'
|
2021-08-11 15:34:10 -05:00
|
|
|
import Countdown from './countdown'
|
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-02-17 11:23:43 -06:00
|
|
|
import { formatSats } from '../lib/format'
|
|
|
|
import * as Yup from 'yup'
|
|
|
|
import Briefcase from '../svgs/briefcase-4-fill.svg'
|
2022-02-03 16:01:42 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-17 11:23:43 -06:00
|
|
|
export function ItemJob ({ item, rank, children }) {
|
|
|
|
const isEmail = Yup.string().email().isValidSync(item.url)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{rank
|
|
|
|
? (
|
|
|
|
<div className={styles.rank}>
|
|
|
|
{rank}
|
|
|
|
</div>)
|
|
|
|
: <div />}
|
|
|
|
<div className={`${styles.item}`}>
|
|
|
|
<Briefcase width={24} height={24} className={styles.case} />
|
|
|
|
<div className={styles.hunk}>
|
|
|
|
<div className={`${styles.main} flex-wrap d-inline`}>
|
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a className={`${styles.title} text-reset mr-2`}>
|
2022-03-07 15:50:13 -06:00
|
|
|
{item.searchTitle
|
|
|
|
? <SearchTitle title={item.searchTitle} />
|
|
|
|
: (
|
|
|
|
<>{item.title}
|
|
|
|
{item.company &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
{item.company}
|
|
|
|
</>}
|
|
|
|
{(item.location || item.remote) &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
{`${item.location || ''}${item.location && item.remote ? ' or ' : ''}${item.remote ? 'Remote' : ''}`}
|
|
|
|
</>}
|
|
|
|
</>)}
|
2022-02-17 11:23:43 -06:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
{/* eslint-disable-next-line */}
|
|
|
|
<a
|
|
|
|
className={`${styles.link}`}
|
|
|
|
target='_blank' href={(isEmail ? 'mailto:' : '') + item.url}
|
|
|
|
>
|
|
|
|
apply
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div className={`${styles.other}`}>
|
2022-03-16 11:35:51 -05:00
|
|
|
<span>{formatSats(item.maxBid)} sats per min</span>
|
2022-02-17 11:23:43 -06:00
|
|
|
<span> \ </span>
|
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a className='text-reset'>{item.ncomments} comments</a>
|
|
|
|
</Link>
|
|
|
|
<span> \ </span>
|
|
|
|
<span>
|
|
|
|
<Link href={`/${item.user.name}`} passHref>
|
|
|
|
<a>@{item.user.name}</a>
|
|
|
|
</Link>
|
|
|
|
<span> </span>
|
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a title={item.createdAt} className='text-reset'>{timeSince(new Date(item.createdAt))}</a>
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
{item.mine &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
<Link href={`/items/${item.id}/edit`} passHref>
|
|
|
|
<a className='text-reset'>
|
|
|
|
edit
|
|
|
|
</a>
|
|
|
|
</Link>
|
2022-02-26 10:41:30 -06:00
|
|
|
{item.status !== 'ACTIVE' && <span className='font-weight-bold text-danger'> {item.status}</span>}
|
2022-02-17 11:23:43 -06:00
|
|
|
</>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{children && (
|
|
|
|
<div className={`${styles.children}`}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-19 13:32:39 -05:00
|
|
|
function FwdUser ({ user }) {
|
|
|
|
return (
|
|
|
|
<div className={styles.other}>
|
|
|
|
100% of tips are forwarded to{' '}
|
|
|
|
<Link href={`/${user.name}`} passHref>
|
|
|
|
<a>@{user.name}</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Item ({ item, rank, showFwdUser, children }) {
|
2021-11-27 12:01:02 -06:00
|
|
|
const mine = item.mine
|
2021-08-11 15:13:10 -05:00
|
|
|
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
|
|
|
|
const [canEdit, setCanEdit] =
|
|
|
|
useState(mine && (Date.now() < editThreshold))
|
2021-09-15 18:42:44 -05:00
|
|
|
const [wrap, setWrap] = useState(false)
|
|
|
|
const titleRef = useRef()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setWrap(
|
2022-02-09 13:15:38 -06:00
|
|
|
Math.ceil(parseFloat(window.getComputedStyle(titleRef.current).lineHeight)) <
|
2021-09-15 18:42:44 -05:00
|
|
|
titleRef.current.clientHeight)
|
|
|
|
}, [])
|
|
|
|
|
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-01-07 10:32:31 -06:00
|
|
|
{item.position ? <Pin width={24} height={24} className={styles.pin} /> : <UpVote item={item} className={styles.upvote} />}
|
2021-04-14 18:56:29 -05:00
|
|
|
<div className={styles.hunk}>
|
2021-09-15 18:42:44 -05:00
|
|
|
<div className={`${styles.main} flex-wrap ${wrap ? 'd-inline' : ''}`}>
|
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}
|
|
|
|
</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
|
|
|
|
className={`${styles.link} ${wrap ? styles.linkSmall : ''}`} target='_blank' href={item.url}
|
|
|
|
rel={item.sats + item.boost >= NOFOLLOW_LIMIT ? null : 'nofollow'}
|
|
|
|
>
|
|
|
|
{item.url.replace(/(^https?:|^)\/\//, '')}
|
|
|
|
</a>
|
|
|
|
</>}
|
2021-04-14 18:56:29 -05:00
|
|
|
</div>
|
2021-04-28 11:30:02 -05:00
|
|
|
<div className={`${styles.other}`}>
|
2022-01-07 10:32:31 -06:00
|
|
|
{!item.position &&
|
|
|
|
<>
|
2022-01-20 17:04:12 -06:00
|
|
|
<span title={`from ${item.upvotes} users (${item.meSats} sats from me)`}>{item.sats} sats</span>
|
2022-01-07 10:32:31 -06:00
|
|
|
<span> \ </span>
|
|
|
|
</>}
|
2021-09-10 13:55:36 -05:00
|
|
|
{item.boost > 0 &&
|
|
|
|
<>
|
|
|
|
<span>{item.boost} boost</span>
|
|
|
|
<span> \ </span>
|
|
|
|
</>}
|
2021-04-15 14:41:02 -05:00
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a className='text-reset'>{item.ncomments} comments</a>
|
|
|
|
</Link>
|
2021-04-14 18:56:29 -05:00
|
|
|
<span> \ </span>
|
2021-04-28 11:30:02 -05:00
|
|
|
<span>
|
|
|
|
<Link href={`/${item.user.name}`} passHref>
|
|
|
|
<a>@{item.user.name}</a>
|
|
|
|
</Link>
|
|
|
|
<span> </span>
|
2021-10-30 11:58:33 -05:00
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a title={item.createdAt} className='text-reset'>{timeSince(new Date(item.createdAt))}</a>
|
|
|
|
</Link>
|
2022-01-13 13:05:43 -06:00
|
|
|
{item.prior &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
<Link href={`/items/${item.prior}`} passHref>
|
|
|
|
<a className='text-reset'>yesterday</a>
|
|
|
|
</Link>
|
|
|
|
</>}
|
2021-04-28 11:30:02 -05:00
|
|
|
</span>
|
2021-08-11 15:13:10 -05:00
|
|
|
{canEdit &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
<Link href={`/items/${item.id}/edit`} passHref>
|
|
|
|
<a className='text-reset'>
|
|
|
|
edit
|
|
|
|
<Countdown
|
|
|
|
date={editThreshold}
|
2021-08-11 15:34:10 -05:00
|
|
|
className=' '
|
2021-08-11 15:13:10 -05:00
|
|
|
onComplete={() => {
|
|
|
|
setCanEdit(false)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</>}
|
2021-04-14 18:56:29 -05:00
|
|
|
</div>
|
2022-04-19 13:32:39 -05:00
|
|
|
{showFwdUser && item.fwdUser && <FwdUser user={item.fwdUser} />}
|
2021-04-13 19:57:32 -05:00
|
|
|
</div>
|
|
|
|
</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
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|