2022-07-21 22:55:05 +00:00
|
|
|
import Item from './item'
|
|
|
|
import ItemJob from './item-job'
|
2021-09-24 21:28:21 +00:00
|
|
|
import Reply from './reply'
|
2021-09-23 17:42:00 +00:00
|
|
|
import Comment from './comment'
|
|
|
|
import Text from './text'
|
2021-09-24 21:28:21 +00:00
|
|
|
import Comments from './comments'
|
2021-09-23 17:42:00 +00:00
|
|
|
import styles from '../styles/item.module.css'
|
|
|
|
import { NOFOLLOW_LIMIT } from '../lib/constants'
|
2021-09-23 22:18:48 +00:00
|
|
|
import { useMe } from './me'
|
2021-09-24 21:28:21 +00:00
|
|
|
import { Button } from 'react-bootstrap'
|
2022-02-12 14:06:41 +00:00
|
|
|
import { TwitterTweetEmbed } from 'react-twitter-embed'
|
2022-02-05 21:40:54 +00:00
|
|
|
import YouTube from 'react-youtube'
|
2022-01-20 20:22:10 +00:00
|
|
|
import useDarkMode from 'use-dark-mode'
|
2022-09-02 16:53:44 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-07-30 13:25:46 +00:00
|
|
|
import Poll from './poll'
|
2022-09-02 16:53:44 +00:00
|
|
|
import { commentsViewed } from '../lib/new-comments'
|
2022-10-26 22:46:01 +00:00
|
|
|
import Related from './related'
|
2023-01-26 16:11:55 +00:00
|
|
|
import PastBounties from './past-bounties'
|
|
|
|
import Check from '../svgs/check-double-line.svg'
|
2023-02-16 22:23:59 +00:00
|
|
|
import Share from './share'
|
|
|
|
import Toc from './table-of-contents'
|
|
|
|
import Link from 'next/link'
|
2023-05-06 21:51:17 +00:00
|
|
|
import { RootProvider } from './root'
|
2021-09-23 17:42:00 +00:00
|
|
|
|
2021-09-24 21:28:21 +00:00
|
|
|
function BioItem ({ item, handleClick }) {
|
2021-09-23 22:18:48 +00:00
|
|
|
const me = useMe()
|
2021-09-23 20:09:07 +00:00
|
|
|
if (!item.text) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ItemText item={item} />
|
2021-09-23 22:18:48 +00:00
|
|
|
{me?.name === item.user.name &&
|
2021-11-12 22:39:52 +00:00
|
|
|
<div className='text-right'>
|
|
|
|
<Button
|
|
|
|
onClick={handleClick}
|
|
|
|
size='md' variant='link'
|
|
|
|
>edit bio
|
|
|
|
</Button>
|
|
|
|
</div>}
|
2022-09-01 21:53:39 +00:00
|
|
|
<Reply item={item} />
|
2021-09-23 20:09:07 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-12 14:06:41 +00:00
|
|
|
function TweetSkeleton () {
|
|
|
|
return (
|
|
|
|
<div className={styles.tweetsSkeleton}>
|
|
|
|
<div className={styles.tweetSkeleton}>
|
|
|
|
<div className={`${styles.img} clouds`} />
|
|
|
|
<div className={styles.content1}>
|
|
|
|
<div className={`${styles.line} clouds`} />
|
|
|
|
<div className={`${styles.line} clouds`} />
|
|
|
|
<div className={`${styles.line} clouds`} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-20 20:22:10 +00:00
|
|
|
function ItemEmbed ({ item }) {
|
|
|
|
const darkMode = useDarkMode()
|
2022-02-12 14:06:41 +00:00
|
|
|
const [overflowing, setOverflowing] = useState(false)
|
|
|
|
const [show, setShow] = useState(false)
|
|
|
|
|
2022-01-21 18:37:36 +00:00
|
|
|
const twitter = item.url?.match(/^https?:\/\/twitter\.com\/(?:#!\/)?\w+\/status(?:es)?\/(?<id>\d+)/)
|
2022-01-20 20:22:10 +00:00
|
|
|
if (twitter?.groups?.id) {
|
2022-02-09 19:15:38 +00:00
|
|
|
return (
|
2022-03-10 16:09:05 +00:00
|
|
|
<div className={`${styles.twitterContainer} ${show ? '' : styles.twitterContained}`}>
|
|
|
|
<TwitterTweetEmbed tweetId={twitter.groups.id} options={{ width: '550px', theme: darkMode.value ? 'dark' : 'light' }} placeholder={<TweetSkeleton />} onLoad={() => setOverflowing(true)} />
|
2022-02-12 14:06:41 +00:00
|
|
|
{overflowing && !show &&
|
|
|
|
<Button size='lg' variant='info' className={styles.twitterShowFull} onClick={() => setShow(true)}>
|
|
|
|
show full tweet
|
|
|
|
</Button>}
|
2022-02-09 19:15:38 +00:00
|
|
|
</div>
|
|
|
|
)
|
2022-01-20 20:22:10 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 00:09:05 +00:00
|
|
|
const youtube = item.url?.match(/(https?:\/\/)?((www\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)(?<id>[_0-9a-z-]+)((?:\?|&)(?:t|start)=(?<start>\d+))?/i)
|
2022-02-05 21:40:54 +00:00
|
|
|
if (youtube?.groups?.id) {
|
|
|
|
return (
|
|
|
|
<div style={{ maxWidth: '640px', paddingRight: '15px' }}>
|
2023-01-14 00:09:05 +00:00
|
|
|
<YouTube
|
|
|
|
videoId={youtube.groups.id} containerClassName={styles.youtubeContainer} opts={{
|
|
|
|
playerVars: {
|
|
|
|
start: youtube?.groups?.start
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
2022-02-05 21:40:54 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-20 20:22:10 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-02-16 22:23:59 +00:00
|
|
|
function FwdUser ({ user }) {
|
|
|
|
return (
|
|
|
|
<div className={styles.other}>
|
2023-06-19 18:21:55 +00:00
|
|
|
100% of zaps are forwarded to{' '}
|
2023-02-16 22:23:59 +00:00
|
|
|
<Link href={`/${user.name}`} passHref>
|
|
|
|
<a>@{user.name}</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-03 22:01:42 +00:00
|
|
|
function TopLevelItem ({ item, noReply, ...props }) {
|
2022-09-29 20:42:33 +00:00
|
|
|
const ItemComponent = item.isJob ? ItemJob : Item
|
2022-02-17 17:23:43 +00:00
|
|
|
|
2021-09-23 20:09:07 +00:00
|
|
|
return (
|
2023-02-16 22:23:59 +00:00
|
|
|
<ItemComponent
|
|
|
|
item={item}
|
2023-05-11 19:34:42 +00:00
|
|
|
full
|
2023-02-16 22:23:59 +00:00
|
|
|
right={
|
|
|
|
<>
|
|
|
|
<Share item={item} />
|
|
|
|
<Toc text={item.text} />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
belowTitle={item.fwdUser && <FwdUser user={item.fwdUser} />}
|
|
|
|
{...props}
|
|
|
|
>
|
2023-01-27 21:01:32 +00:00
|
|
|
<div className={styles.fullItemContainer}>
|
|
|
|
{item.text && <ItemText item={item} />}
|
|
|
|
{item.url && <ItemEmbed item={item} />}
|
|
|
|
{item.poll && <Poll item={item} />}
|
|
|
|
{item.bounty &&
|
|
|
|
<div className='font-weight-bold mt-2'>
|
|
|
|
{item.bountyPaidTo?.length
|
|
|
|
? (
|
|
|
|
<div className='px-3 py-1 d-inline-block bg-grey-medium rounded text-success'>
|
|
|
|
<Check className='fill-success' /> {item.bounty} sats paid
|
|
|
|
</div>)
|
|
|
|
: (
|
|
|
|
<div className='px-3 py-1 d-inline-block bg-grey-darkmode rounded text-light'>
|
|
|
|
{item.bounty} sats bounty
|
|
|
|
</div>)}
|
|
|
|
</div>}
|
|
|
|
</div>
|
2022-10-26 22:46:01 +00:00
|
|
|
{!noReply &&
|
|
|
|
<>
|
2023-05-11 00:41:17 +00:00
|
|
|
<Reply item={item} replyOpen placeholder={item.ncomments ? undefined : 'start the conversation ...'} />
|
2023-01-26 16:11:55 +00:00
|
|
|
{!item.position && !item.isJob && !item.parentId && !item.bounty > 0 && <Related title={item.title} itemId={item.id} />}
|
|
|
|
{item.bounty > 0 && <PastBounties item={item} />}
|
2022-10-26 22:46:01 +00:00
|
|
|
</>}
|
2022-02-17 17:23:43 +00:00
|
|
|
</ItemComponent>
|
2021-09-23 20:09:07 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function ItemText ({ item }) {
|
2022-07-13 23:00:48 +00:00
|
|
|
return <Text topLevel nofollow={item.sats + item.boost < NOFOLLOW_LIMIT}>{item.searchText || item.text}</Text>
|
2021-09-23 20:09:07 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:28:21 +00:00
|
|
|
export default function ItemFull ({ item, bio, ...props }) {
|
2022-09-02 16:53:44 +00:00
|
|
|
useEffect(() => {
|
|
|
|
commentsViewed(item)
|
|
|
|
}, [item.lastCommentAt])
|
|
|
|
|
2021-09-23 17:42:00 +00:00
|
|
|
return (
|
2023-05-06 21:51:17 +00:00
|
|
|
<RootProvider root={item.root || item}>
|
2021-09-23 17:42:00 +00:00
|
|
|
{item.parentId
|
2022-07-13 23:00:48 +00:00
|
|
|
? <Comment topLevel item={item} replyOpen includeParent noComments {...props} />
|
2021-11-12 22:39:52 +00:00
|
|
|
: (
|
|
|
|
<div className='mt-1'>{
|
|
|
|
bio
|
2021-09-24 21:28:21 +00:00
|
|
|
? <BioItem item={item} {...props} />
|
|
|
|
: <TopLevelItem item={item} {...props} />
|
2021-11-12 22:39:52 +00:00
|
|
|
}
|
|
|
|
</div>)}
|
2021-09-24 21:28:21 +00:00
|
|
|
{item.comments &&
|
|
|
|
<div className={styles.comments}>
|
2023-03-19 15:43:33 +00:00
|
|
|
<Comments parentId={item.id} pinned={item.position} commentSats={item.commentSats} comments={item.comments} />
|
2021-09-24 21:28:21 +00:00
|
|
|
</div>}
|
2023-05-06 21:51:17 +00:00
|
|
|
</RootProvider>
|
2021-09-23 17:42:00 +00:00
|
|
|
)
|
|
|
|
}
|