import Link from 'next/link' import styles from './item.module.css' import { timeSince } from '../lib/time' import UpVote from './upvote' import { useEffect, useRef, useState } from 'react' import Countdown from './countdown' import { NOFOLLOW_LIMIT } from '../lib/constants' import Pin from '../svgs/pushpin-fill.svg' import reactStringReplace from 'react-string-replace' import { formatSats } from '../lib/format' import * as Yup from 'yup' import Briefcase from '../svgs/briefcase-4-fill.svg' function SearchTitle ({ title }) { return reactStringReplace(title, /:high\[([^\]]+)\]/g, (match, i) => { return {match} }) } export function ItemJob ({ item, rank, children }) { const isEmail = Yup.string().email().isValidSync(item.url) return ( <> {rank ? (
{rank}
) :
}
{item.searchTitle ? : ( <>{item.title} {item.company && <> \ {item.company} } {(item.location || item.remote) && <> \ {`${item.location || ''}${item.location && item.remote ? ' or ' : ''}${item.remote ? 'Remote' : ''}`} } )} {/* eslint-disable-next-line */} apply
{formatSats(item.maxBid)} sats \ {item.ncomments} comments \ @{item.user.name} {timeSince(new Date(item.createdAt))} {item.mine && <> \ edit {item.status !== 'ACTIVE' && {item.status}} }
{children && (
{children}
)} ) } export default function Item ({ item, rank, children }) { const mine = item.mine const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000 const [canEdit, setCanEdit] = useState(mine && (Date.now() < editThreshold)) const [wrap, setWrap] = useState(false) const titleRef = useRef() useEffect(() => { setWrap( Math.ceil(parseFloat(window.getComputedStyle(titleRef.current).lineHeight)) < titleRef.current.clientHeight) }, []) return ( <> {rank ? (
{rank}
) :
}
{item.position ? : }
{!item.position && <> {item.sats} sats \ } {item.boost > 0 && <> {item.boost} boost \ } {item.ncomments} comments \ @{item.user.name} {timeSince(new Date(item.createdAt))} {item.prior && <> \ yesterday } {canEdit && <> \ edit { setCanEdit(false) }} /> }
{children && (
{children}
)} ) } export function ItemSkeleton ({ rank, children }) { return ( <> {rank ? (
{rank}
) :
}
{children && (
{children}
)} ) }