chore(git): merge pull request #209 from fixes/adv-comments-30-1-25 into staging
All checks were successful
Release to Staging / build_and_release (push) Successful in 1m9s
All checks were successful
Release to Staging / build_and_release (push) Successful in 1m9s
Reviewed-on: #209
This commit is contained in:
commit
c217ed15b8
@ -99,7 +99,7 @@ export const Comment = ({ comment }: CommentProps) => {
|
|||||||
<div className='IBMSMSMBSSCL_CommentActions'>
|
<div className='IBMSMSMBSSCL_CommentActions'>
|
||||||
<div className='IBMSMSMBSSCL_CommentActionsInside'>
|
<div className='IBMSMSMBSSCL_CommentActionsInside'>
|
||||||
<Reactions {...comment.event.rawEvent()} />
|
<Reactions {...comment.event.rawEvent()} />
|
||||||
<div
|
{/* <div
|
||||||
className='IBMSMSMBSSCL_CAElement IBMSMSMBSSCL_CAERepost'
|
className='IBMSMSMBSSCL_CAElement IBMSMSMBSSCL_CAERepost'
|
||||||
style={{ cursor: 'not-allowed' }}
|
style={{ cursor: 'not-allowed' }}
|
||||||
>
|
>
|
||||||
@ -117,7 +117,7 @@ export const Comment = ({ comment }: CommentProps) => {
|
|||||||
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
||||||
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> */}
|
||||||
{typeof profile?.lud16 !== 'undefined' && profile.lud16 !== '' && (
|
{typeof profile?.lud16 !== 'undefined' && profile.lud16 !== '' && (
|
||||||
<Zap {...comment.event.rawEvent()} />
|
<Zap {...comment.event.rawEvent()} />
|
||||||
)}
|
)}
|
||||||
|
@ -7,7 +7,7 @@ export const CommentContent = ({ content }: CommentContentProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p className='IBMSMSMBSSCL_CBText'>{text} </p>
|
<p className='IBMSMSMBSSCL_CBText'>{text}</p>
|
||||||
{isTextOverflowing && (
|
{isTextOverflowing && (
|
||||||
<div className='IBMSMSMBSSCL_CBExpand' onClick={toggle}>
|
<div className='IBMSMSMBSSCL_CBExpand' onClick={toggle}>
|
||||||
<p>{isExpanded ? 'Hide' : 'View'} full post</p>
|
<p>{isExpanded ? 'Hide' : 'View'} full post</p>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatDate } from 'date-fns'
|
import { formatDate } from 'date-fns'
|
||||||
import { useBodyScrollDisable, useNDKContext } from 'hooks'
|
import { useBodyScrollDisable, useNDKContext, useReplies } from 'hooks'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'
|
import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
@ -10,7 +10,7 @@ import {
|
|||||||
useParams
|
useParams
|
||||||
} from 'react-router-dom'
|
} from 'react-router-dom'
|
||||||
import { getBlogPageRoute, getModPageRoute, getProfilePageRoute } from 'routes'
|
import { getBlogPageRoute, getModPageRoute, getProfilePageRoute } from 'routes'
|
||||||
import { UserProfile } from 'types'
|
import { CommentEvent, UserProfile } from 'types'
|
||||||
import { CommentsLoaderResult } from 'types/comments'
|
import { CommentsLoaderResult } from 'types/comments'
|
||||||
import { adjustTextareaHeight, handleCommentSubmit, hexToNpub } from 'utils'
|
import { adjustTextareaHeight, handleCommentSubmit, hexToNpub } from 'utils'
|
||||||
import { Reactions } from './Reactions'
|
import { Reactions } from './Reactions'
|
||||||
@ -19,6 +19,7 @@ import { NDKKind } from '@nostr-dev-kit/ndk'
|
|||||||
import { Comment } from './Comment'
|
import { Comment } from './Comment'
|
||||||
import { useComments } from 'hooks/useComments'
|
import { useComments } from 'hooks/useComments'
|
||||||
import { CommentContent } from './CommentContent'
|
import { CommentContent } from './CommentContent'
|
||||||
|
import { Dots } from 'components/Spinner'
|
||||||
|
|
||||||
export const CommentsPopup = () => {
|
export const CommentsPopup = () => {
|
||||||
const { naddr } = useParams()
|
const { naddr } = useParams()
|
||||||
@ -35,7 +36,13 @@ export const CommentsPopup = () => {
|
|||||||
: undefined
|
: undefined
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const { event, parents } = useLoaderData() as CommentsLoaderResult
|
const { event } = useLoaderData() as CommentsLoaderResult
|
||||||
|
const {
|
||||||
|
size,
|
||||||
|
parent: replyEvent,
|
||||||
|
isComplete,
|
||||||
|
root: rootEvent
|
||||||
|
} = useReplies(event.tagValue('e'))
|
||||||
const isRoot = event.tagValue('a') === event.tagValue('A')
|
const isRoot = event.tagValue('a') === event.tagValue('A')
|
||||||
const [profile, setProfile] = useState<UserProfile>()
|
const [profile, setProfile] = useState<UserProfile>()
|
||||||
const { commentEvents, setCommentEvents } = useComments(
|
const { commentEvents, setCommentEvents } = useComments(
|
||||||
@ -56,7 +63,6 @@ export const CommentsPopup = () => {
|
|||||||
[event.pubkey]
|
[event.pubkey]
|
||||||
)
|
)
|
||||||
|
|
||||||
const replyEvent = parents.length > 0 ? parents[0] : undefined
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
@ -68,7 +74,30 @@ export const CommentsPopup = () => {
|
|||||||
adjustTextareaHeight(e.currentTarget)
|
adjustTextareaHeight(e.currentTarget)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleSubmit = handleCommentSubmit(event, setCommentEvents, ndk)
|
const [visible, setVisible] = useState<CommentEvent[]>([])
|
||||||
|
const discoveredCount = commentEvents.length - visible.length
|
||||||
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
useEffect(() => {
|
||||||
|
// Initial loading to indicate comments fetching (stop after 5 seconds)
|
||||||
|
const t = window.setTimeout(() => setIsLoading(false), 5000)
|
||||||
|
return () => {
|
||||||
|
window.clearTimeout(t)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
useEffect(() => {
|
||||||
|
if (isLoading) {
|
||||||
|
setVisible(commentEvents)
|
||||||
|
}
|
||||||
|
}, [commentEvents, isLoading])
|
||||||
|
const handleDiscoveredClick = () => {
|
||||||
|
setVisible(commentEvents)
|
||||||
|
}
|
||||||
|
const handleSubmit = handleCommentSubmit(
|
||||||
|
event,
|
||||||
|
setCommentEvents,
|
||||||
|
setVisible,
|
||||||
|
ndk
|
||||||
|
)
|
||||||
|
|
||||||
const handleComment = async () => {
|
const handleComment = async () => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
@ -110,6 +139,9 @@ export const CommentsPopup = () => {
|
|||||||
<div className='IBMSMSMBSSCL_CTO'>
|
<div className='IBMSMSMBSSCL_CTO'>
|
||||||
{replyEvent && (
|
{replyEvent && (
|
||||||
<Link
|
<Link
|
||||||
|
style={{
|
||||||
|
...(!isComplete ? { pointerEvents: 'none' } : {})
|
||||||
|
}}
|
||||||
className='IBMSMSMBSSCL_CTOLink'
|
className='IBMSMSMBSSCL_CTOLink'
|
||||||
to={baseUrl + replyEvent.encode()}
|
to={baseUrl + replyEvent.encode()}
|
||||||
>
|
>
|
||||||
@ -126,16 +158,20 @@ export const CommentsPopup = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
<p className='IBMSMSMBSSCL_CTOText'>
|
<p className='IBMSMSMBSSCL_CTOText'>
|
||||||
Reply Depth: <span>{parents.length}</span>
|
Reply Depth: <span>{size}</span>
|
||||||
|
{!isComplete && <Dots />}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{!isRoot && (
|
{!isRoot && rootEvent && (
|
||||||
<Link
|
<Link
|
||||||
|
style={{
|
||||||
|
...(!isComplete ? { pointerEvents: 'none' } : {})
|
||||||
|
}}
|
||||||
className='btn btnMain IBMSMSMBSSCL_CTOBtn'
|
className='btn btnMain IBMSMSMBSSCL_CTOBtn'
|
||||||
type='button'
|
type='button'
|
||||||
to={'..'}
|
to={baseUrl + rootEvent.encode()}
|
||||||
>
|
>
|
||||||
Main Post
|
Main Post {!isComplete && <Dots />}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -185,7 +221,7 @@ export const CommentsPopup = () => {
|
|||||||
<div className='IBMSMSMBSSCL_CommentActionsInside'>
|
<div className='IBMSMSMBSSCL_CommentActionsInside'>
|
||||||
<Reactions {...event.rawEvent()} />
|
<Reactions {...event.rawEvent()} />
|
||||||
|
|
||||||
<div
|
{/* <div
|
||||||
className='IBMSMSMBSSCL_CAElement IBMSMSMBSSCL_CAERepost'
|
className='IBMSMSMBSSCL_CAElement IBMSMSMBSSCL_CAERepost'
|
||||||
style={{ cursor: 'not-allowed' }}
|
style={{ cursor: 'not-allowed' }}
|
||||||
>
|
>
|
||||||
@ -203,7 +239,7 @@ export const CommentsPopup = () => {
|
|||||||
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
||||||
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> */}
|
||||||
|
|
||||||
{typeof profile?.lud16 !== 'undefined' &&
|
{typeof profile?.lud16 !== 'undefined' &&
|
||||||
profile.lud16 !== '' && <Zap {...event.rawEvent()} />}
|
profile.lud16 !== '' && <Zap {...event.rawEvent()} />}
|
||||||
@ -262,6 +298,26 @@ export const CommentsPopup = () => {
|
|||||||
<>
|
<>
|
||||||
<h3 className='IBMSMSMBSSCL_CommentNoteRepliesTitle'>
|
<h3 className='IBMSMSMBSSCL_CommentNoteRepliesTitle'>
|
||||||
Replies
|
Replies
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
className='btnMain IBMSMSMBSSCL_CommentNoteRepliesTitleBtn'
|
||||||
|
onClick={
|
||||||
|
discoveredCount ? handleDiscoveredClick : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
Discovering replies
|
||||||
|
<Dots />
|
||||||
|
</>
|
||||||
|
) : discoveredCount ? (
|
||||||
|
<>Load {discoveredCount} discovered replies</>
|
||||||
|
) : (
|
||||||
|
<>No new replies</>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
</h3>
|
</h3>
|
||||||
<div className='pUMCB_RepliesToPrime'>
|
<div className='pUMCB_RepliesToPrime'>
|
||||||
{commentEvents.map((reply) => (
|
{commentEvents.map((reply) => (
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Spinner } from 'components/Spinner'
|
import { Dots } from 'components/Spinner'
|
||||||
import { useNDKContext } from 'hooks'
|
import { useNDKContext } from 'hooks'
|
||||||
import { useComments } from 'hooks/useComments'
|
import { useComments } from 'hooks/useComments'
|
||||||
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react'
|
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react'
|
||||||
@ -48,12 +48,16 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
setCommentCount(commentEvents.length)
|
setCommentCount(commentEvents.length)
|
||||||
}, [commentEvents, setCommentCount])
|
}, [commentEvents, setCommentCount])
|
||||||
|
|
||||||
const handleSubmit = handleCommentSubmit(event, setCommentEvents, ndk)
|
|
||||||
|
|
||||||
const handleDiscoveredClick = () => {
|
const handleDiscoveredClick = () => {
|
||||||
setVisible(commentEvents)
|
setVisible(commentEvents)
|
||||||
}
|
}
|
||||||
const [visible, setVisible] = useState<CommentEvent[]>([])
|
const [visible, setVisible] = useState<CommentEvent[]>([])
|
||||||
|
const handleSubmit = handleCommentSubmit(
|
||||||
|
event,
|
||||||
|
setCommentEvents,
|
||||||
|
setVisible,
|
||||||
|
ndk
|
||||||
|
)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
setVisible(commentEvents)
|
setVisible(commentEvents)
|
||||||
@ -93,17 +97,24 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
{/* Hide comment form if aTag is missing */}
|
{/* Hide comment form if aTag is missing */}
|
||||||
{!!addressable.aTag && <CommentForm handleSubmit={handleSubmit} />}
|
{!!addressable.aTag && <CommentForm handleSubmit={handleSubmit} />}
|
||||||
<div>
|
<div>
|
||||||
{isLoading ? (
|
|
||||||
<Spinner />
|
|
||||||
) : (
|
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
className='btnMain'
|
className='btnMain'
|
||||||
onClick={discoveredCount ? handleDiscoveredClick : undefined}
|
onClick={discoveredCount ? handleDiscoveredClick : undefined}
|
||||||
>
|
>
|
||||||
<span>Load {discoveredCount} discovered comments</span>
|
<span>
|
||||||
</button>
|
{isLoading ? (
|
||||||
|
<>
|
||||||
|
Discovering comments
|
||||||
|
<Dots />
|
||||||
|
</>
|
||||||
|
) : discoveredCount ? (
|
||||||
|
<>Load {discoveredCount} discovered comments</>
|
||||||
|
) : (
|
||||||
|
<>No new comments</>
|
||||||
)}
|
)}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<Filter
|
<Filter
|
||||||
filterOptions={filterOptions}
|
filterOptions={filterOptions}
|
||||||
|
@ -11,3 +11,4 @@ export * from './useScrollDisable'
|
|||||||
export * from './useLocalStorage'
|
export * from './useLocalStorage'
|
||||||
export * from './useSessionStorage'
|
export * from './useSessionStorage'
|
||||||
export * from './useLocalCache'
|
export * from './useLocalCache'
|
||||||
|
export * from './useReplies'
|
||||||
|
53
src/hooks/useReplies.tsx
Normal file
53
src/hooks/useReplies.tsx
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import {
|
||||||
|
NDKEvent,
|
||||||
|
NDKKind,
|
||||||
|
NDKSubscriptionCacheUsage
|
||||||
|
} from '@nostr-dev-kit/ndk'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useNDKContext } from './useNDKContext'
|
||||||
|
import { useDidMount } from './useDidMount'
|
||||||
|
|
||||||
|
export const useReplies = (eTag: string | undefined) => {
|
||||||
|
const { ndk } = useNDKContext()
|
||||||
|
const [replies, setReplies] = useState<NDKEvent[]>([])
|
||||||
|
const [isComplete, setIsComplete] = useState(false)
|
||||||
|
|
||||||
|
useDidMount(async () => {
|
||||||
|
if (!eTag) {
|
||||||
|
setIsComplete(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let eDepth: string | undefined = eTag
|
||||||
|
while (eDepth) {
|
||||||
|
const previousReply = await ndk.fetchEvent(
|
||||||
|
{
|
||||||
|
kinds: [NDKKind.Text, NDKKind.GenericReply],
|
||||||
|
ids: [eDepth]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (previousReply) {
|
||||||
|
setReplies((p) => {
|
||||||
|
if (p.findIndex((p) => p.id === previousReply.id) === -1) {
|
||||||
|
p.push(previousReply)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
eDepth = previousReply.tagValue('e')
|
||||||
|
} else {
|
||||||
|
eDepth = undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setIsComplete(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
size: replies.length,
|
||||||
|
isComplete,
|
||||||
|
parent: replies.length > 0 ? replies[0] : undefined,
|
||||||
|
root: isComplete ? replies[replies.length - 1] : undefined
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'
|
|
||||||
import { NDKContextType } from 'contexts/NDKContext'
|
import { NDKContextType } from 'contexts/NDKContext'
|
||||||
import { LoaderFunctionArgs, redirect } from 'react-router-dom'
|
import { LoaderFunctionArgs, redirect } from 'react-router-dom'
|
||||||
import { CommentsLoaderResult } from 'types/comments'
|
import { CommentsLoaderResult } from 'types/comments'
|
||||||
@ -21,23 +20,8 @@ export const commentsLoader =
|
|||||||
throw new Error('We are unable to find the comment on the relays')
|
throw new Error('We are unable to find the comment on the relays')
|
||||||
}
|
}
|
||||||
|
|
||||||
const replies: NDKEvent[] = []
|
|
||||||
let eTag: string | undefined = replyEvent.tagValue('e')
|
|
||||||
while (eTag) {
|
|
||||||
const prev = await ndkContext.ndk.fetchEvent({
|
|
||||||
kinds: [NDKKind.Text, NDKKind.GenericReply],
|
|
||||||
ids: [eTag]
|
|
||||||
})
|
|
||||||
if (prev) {
|
|
||||||
replies.push(prev)
|
|
||||||
eTag = prev.tagValue('e')
|
|
||||||
} else {
|
|
||||||
eTag = undefined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const result: Partial<CommentsLoaderResult> = {
|
const result: Partial<CommentsLoaderResult> = {
|
||||||
event: replyEvent,
|
event: replyEvent
|
||||||
parents: replies
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.IBMSMSMBSSCL_CBText {
|
.IBMSMSMBSSCL_CBText {
|
||||||
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
.IBMSMSMBSSCL_CBTextStatus {
|
.IBMSMSMBSSCL_CBTextStatus {
|
||||||
@ -478,6 +479,13 @@ hover {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0 0 15px 0;
|
margin: 0 0 15px 0;
|
||||||
color: rgba(255, 255, 255, 0.5);
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.IBMSMSMBSSCL_CommentNoteRepliesTitleBtn {
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.IBMSMSMBSSCL_CAElementLoadWrapper {
|
.IBMSMSMBSSCL_CAElementLoadWrapper {
|
||||||
|
@ -2,7 +2,6 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'
|
|||||||
|
|
||||||
export interface CommentsLoaderResult {
|
export interface CommentsLoaderResult {
|
||||||
event: NDKEvent
|
event: NDKEvent
|
||||||
parents: NDKEvent[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SortByEnum {
|
export enum SortByEnum {
|
||||||
|
@ -6,6 +6,7 @@ import { log, LogType } from './utils'
|
|||||||
export function handleCommentSubmit(
|
export function handleCommentSubmit(
|
||||||
event: NDKEvent | undefined,
|
event: NDKEvent | undefined,
|
||||||
setCommentEvents: React.Dispatch<React.SetStateAction<CommentEvent[]>>,
|
setCommentEvents: React.Dispatch<React.SetStateAction<CommentEvent[]>>,
|
||||||
|
setVisible: React.Dispatch<React.SetStateAction<CommentEvent[]>>,
|
||||||
ndk: NDK
|
ndk: NDK
|
||||||
) {
|
) {
|
||||||
return async (content: string): Promise<boolean> => {
|
return async (content: string): Promise<boolean> => {
|
||||||
@ -19,13 +20,18 @@ export function handleCommentSubmit(
|
|||||||
const reply = event.reply()
|
const reply = event.reply()
|
||||||
reply.content = content.trim()
|
reply.content = content.trim()
|
||||||
|
|
||||||
setCommentEvents((prev) => [
|
setCommentEvents((prev) => {
|
||||||
|
const newCommentEvents = [
|
||||||
{
|
{
|
||||||
event: reply,
|
event: reply,
|
||||||
status: CommentEventStatus.Publishing
|
status: CommentEventStatus.Publishing
|
||||||
},
|
},
|
||||||
...prev
|
...prev
|
||||||
])
|
]
|
||||||
|
setVisible(newCommentEvents)
|
||||||
|
return newCommentEvents
|
||||||
|
})
|
||||||
|
|
||||||
if (!ndk.signer) {
|
if (!ndk.signer) {
|
||||||
ndk.signer = new NDKNip07Signer()
|
ndk.signer = new NDKNip07Signer()
|
||||||
}
|
}
|
||||||
@ -33,8 +39,8 @@ export function handleCommentSubmit(
|
|||||||
id = reply.id
|
id = reply.id
|
||||||
const relaySet = await reply.publish()
|
const relaySet = await reply.publish()
|
||||||
if (relaySet.size) {
|
if (relaySet.size) {
|
||||||
setCommentEvents((prev) =>
|
setCommentEvents((prev) => {
|
||||||
prev.map((ce) => {
|
const newCommentEvents = prev.map((ce) => {
|
||||||
if (ce.event.id === reply.id) {
|
if (ce.event.id === reply.id) {
|
||||||
return {
|
return {
|
||||||
event: ce.event,
|
event: ce.event,
|
||||||
@ -43,23 +49,28 @@ export function handleCommentSubmit(
|
|||||||
}
|
}
|
||||||
return ce
|
return ce
|
||||||
})
|
})
|
||||||
)
|
setVisible(newCommentEvents)
|
||||||
|
return newCommentEvents
|
||||||
|
})
|
||||||
// when an event is successfully published remove the status from it after 15 seconds
|
// when an event is successfully published remove the status from it after 15 seconds
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setCommentEvents((prev) =>
|
setCommentEvents((prev) => {
|
||||||
prev.map((ce) => {
|
const newCommentEvents = prev.map((ce) => {
|
||||||
if (ce.event.id === reply.id) {
|
if (ce.event.id === reply.id) {
|
||||||
delete ce.status
|
delete ce.status
|
||||||
}
|
}
|
||||||
|
|
||||||
return ce
|
return ce
|
||||||
})
|
})
|
||||||
)
|
setVisible(newCommentEvents)
|
||||||
|
return newCommentEvents
|
||||||
|
})
|
||||||
}, 15000)
|
}, 15000)
|
||||||
|
return true
|
||||||
} else {
|
} else {
|
||||||
log(true, LogType.Error, 'Publishing reply failed.')
|
log(true, LogType.Error, 'Publishing reply failed.')
|
||||||
setCommentEvents((prev) =>
|
setCommentEvents((prev) => {
|
||||||
prev.map((ce) => {
|
const newCommentEvents = prev.map((ce) => {
|
||||||
if (ce.event.id === reply.id) {
|
if (ce.event.id === reply.id) {
|
||||||
return {
|
return {
|
||||||
event: ce.event,
|
event: ce.event,
|
||||||
@ -68,14 +79,16 @@ export function handleCommentSubmit(
|
|||||||
}
|
}
|
||||||
return ce
|
return ce
|
||||||
})
|
})
|
||||||
)
|
setVisible(newCommentEvents)
|
||||||
}
|
return newCommentEvents
|
||||||
|
})
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error('An error occurred in publishing reply.')
|
toast.error('An error occurred in publishing reply.')
|
||||||
log(true, LogType.Error, 'An error occurred in publishing reply.', error)
|
log(true, LogType.Error, 'An error occurred in publishing reply.', error)
|
||||||
setCommentEvents((prev) =>
|
setCommentEvents((prev) => {
|
||||||
prev.map((ce) => {
|
const newCommentEvents = prev.map((ce) => {
|
||||||
if (ce.event.id === id) {
|
if (ce.event.id === id) {
|
||||||
return {
|
return {
|
||||||
event: ce.event,
|
event: ce.event,
|
||||||
@ -84,7 +97,9 @@ export function handleCommentSubmit(
|
|||||||
}
|
}
|
||||||
return ce
|
return ce
|
||||||
})
|
})
|
||||||
)
|
setVisible(newCommentEvents)
|
||||||
|
return newCommentEvents
|
||||||
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user