2021-04-14 23:56:29 +00:00
|
|
|
import Link from 'next/link'
|
2021-04-14 00:57:32 +00:00
|
|
|
import styles from './item.module.css'
|
2021-04-18 18:50:04 +00:00
|
|
|
import { timeSince } from '../lib/time'
|
2021-04-22 22:14:32 +00:00
|
|
|
import UpVote from './upvote'
|
2021-08-11 20:13:10 +00:00
|
|
|
import { useMe } from './me'
|
|
|
|
import { useState } from 'react'
|
2021-08-11 20:34:10 +00:00
|
|
|
import Countdown from './countdown'
|
2021-09-02 18:11:27 +00:00
|
|
|
import { NOFOLLOW_LIMIT } from '../lib/constants'
|
2021-04-14 00:57:32 +00:00
|
|
|
|
2021-04-22 22:14:32 +00:00
|
|
|
export default function Item ({ item, rank, children }) {
|
2021-08-11 20:13:10 +00:00
|
|
|
const me = useMe()
|
|
|
|
const mine = me?.id === item.user.id
|
|
|
|
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
|
|
|
|
const [canEdit, setCanEdit] =
|
|
|
|
useState(mine && (Date.now() < editThreshold))
|
2021-04-14 00:57:32 +00:00
|
|
|
return (
|
2021-04-14 23:56:29 +00:00
|
|
|
<>
|
2021-04-22 22:14:32 +00:00
|
|
|
{rank
|
|
|
|
? (
|
|
|
|
<div className={styles.rank}>
|
|
|
|
{rank}
|
|
|
|
</div>)
|
|
|
|
: <div />}
|
2021-04-14 23:56:29 +00:00
|
|
|
<div className={styles.item}>
|
2021-04-28 16:30:02 +00:00
|
|
|
<UpVote itemId={item.id} meSats={item.meSats} className={styles.upvote} />
|
2021-04-14 23:56:29 +00:00
|
|
|
<div className={styles.hunk}>
|
2021-07-14 22:24:19 +00:00
|
|
|
<div className={`${styles.main} flex-wrap`}>
|
2021-04-14 23:56:29 +00:00
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
2021-07-14 22:24:19 +00:00
|
|
|
<a className={`${styles.title} text-reset mr-2`}>{item.title}</a>
|
2021-04-14 23:56:29 +00:00
|
|
|
</Link>
|
2021-05-20 19:11:58 +00:00
|
|
|
{item.url &&
|
2021-07-08 20:13:52 +00:00
|
|
|
<a
|
|
|
|
className={styles.link} target='_blank' href={item.url} // eslint-disable-line
|
2021-09-02 18:11:27 +00:00
|
|
|
rel={item.sats + item.boost >= NOFOLLOW_LIMIT ? null : 'nofollow'}
|
2021-07-08 20:13:52 +00:00
|
|
|
>
|
2021-05-20 19:11:58 +00:00
|
|
|
{item.url.replace(/(^https?:|^)\/\//, '')}
|
|
|
|
</a>}
|
2021-04-14 23:56:29 +00:00
|
|
|
</div>
|
2021-04-28 16:30:02 +00:00
|
|
|
<div className={`${styles.other}`}>
|
2021-04-14 23:56:29 +00:00
|
|
|
<span>{item.sats} sats</span>
|
2021-04-28 16:30:02 +00:00
|
|
|
<span> \ </span>
|
|
|
|
<span>{item.boost} boost</span>
|
2021-04-14 23:56:29 +00:00
|
|
|
<span> \ </span>
|
2021-04-15 19:41:02 +00:00
|
|
|
<Link href={`/items/${item.id}`} passHref>
|
|
|
|
<a className='text-reset'>{item.ncomments} comments</a>
|
|
|
|
</Link>
|
2021-04-14 23:56:29 +00:00
|
|
|
<span> \ </span>
|
2021-04-28 16:30:02 +00:00
|
|
|
<span>
|
|
|
|
<Link href={`/${item.user.name}`} passHref>
|
|
|
|
<a>@{item.user.name}</a>
|
|
|
|
</Link>
|
|
|
|
<span> </span>
|
|
|
|
<span>{timeSince(new Date(item.createdAt))}</span>
|
|
|
|
</span>
|
2021-08-11 20:13:10 +00:00
|
|
|
{canEdit &&
|
|
|
|
<>
|
|
|
|
<span> \ </span>
|
|
|
|
<Link href={`/items/${item.id}/edit`} passHref>
|
|
|
|
<a className='text-reset'>
|
|
|
|
edit
|
|
|
|
<Countdown
|
|
|
|
date={editThreshold}
|
2021-08-11 20:34:10 +00:00
|
|
|
className=' '
|
2021-08-11 20:13:10 +00:00
|
|
|
onComplete={() => {
|
|
|
|
setCanEdit(false)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</>}
|
2021-04-14 23:56:29 +00:00
|
|
|
</div>
|
2021-04-14 00:57:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-14 23:56:29 +00:00
|
|
|
{children && (
|
|
|
|
<div className={styles.children}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2021-04-14 00:57:32 +00:00
|
|
|
)
|
|
|
|
}
|
2021-04-22 22:14:32 +00:00
|
|
|
|
2021-04-27 00:55:48 +00:00
|
|
|
export function ItemSkeleton ({ rank, children }) {
|
2021-04-22 22:14:32 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{rank &&
|
|
|
|
<div className={styles.rank}>
|
|
|
|
{rank}
|
|
|
|
</div>}
|
|
|
|
<div className={`${styles.item} ${styles.skeleton}`}>
|
2021-04-28 19:30:14 +00:00
|
|
|
<UpVote className={styles.upvote} />
|
2021-04-22 22:14:32 +00: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 22:52:03 +00:00
|
|
|
<span className={`${styles.otherItem} clouds`} />
|
2021-04-22 22:14:32 +00: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-27 00:55:48 +00:00
|
|
|
{children && (
|
|
|
|
<div className={styles.children}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
2021-04-22 22:14:32 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|