blog post and other fixes/additions #124
@ -62,8 +62,8 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Initial loading to indicate comments fetching (stop after 15 seconds)
|
// Initial loading to indicate comments fetching (stop after 5 seconds)
|
||||||
const t = window.setTimeout(() => setIsLoading(false), 15000)
|
const t = window.setTimeout(() => setIsLoading(false), 5000)
|
||||||
return () => {
|
return () => {
|
||||||
window.clearTimeout(t)
|
window.clearTimeout(t)
|
||||||
}
|
}
|
||||||
@ -185,8 +185,18 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDiscoveredClick = () => {
|
||||||
|
setVisible(commentEvents)
|
||||||
|
}
|
||||||
|
const [visible, setVisible] = useState<CommentEvent[]>([])
|
||||||
|
useEffect(() => {
|
||||||
|
if (isLoading) {
|
||||||
|
setVisible(commentEvents)
|
||||||
|
}
|
||||||
|
}, [commentEvents, isLoading])
|
||||||
|
|
||||||
const comments = useMemo(() => {
|
const comments = useMemo(() => {
|
||||||
let filteredComments = commentEvents
|
let filteredComments = visible
|
||||||
if (filterOptions.author === AuthorFilterEnum.Creator_Comments) {
|
if (filterOptions.author === AuthorFilterEnum.Creator_Comments) {
|
||||||
filteredComments = filteredComments.filter(
|
filteredComments = filteredComments.filter(
|
||||||
(comment) => comment.pubkey === addressable.author
|
(comment) => comment.pubkey === addressable.author
|
||||||
@ -200,14 +210,28 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return filteredComments
|
return filteredComments
|
||||||
}, [commentEvents, filterOptions, addressable.author])
|
}, [visible, filterOptions.author, filterOptions.sort, addressable.author])
|
||||||
|
|
||||||
|
const discoveredCount = commentEvents.length - visible.length
|
||||||
return (
|
return (
|
||||||
<div className='IBMSMSMBSSCommentsWrapper'>
|
<div className='IBMSMSMBSSCommentsWrapper'>
|
||||||
<h4 className='IBMSMSMBSSTitle'>Comments</h4>
|
<h4 className='IBMSMSMBSSTitle'>Comments</h4>
|
||||||
<div className='IBMSMSMBSSComments'>
|
<div className='IBMSMSMBSSComments'>
|
||||||
{/* 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>
|
||||||
|
{isLoading ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
className='btnMain'
|
||||||
|
onClick={discoveredCount ? handleDiscoveredClick : undefined}
|
||||||
|
>
|
||||||
|
<span>Load {discoveredCount} discovered comments</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Filter
|
<Filter
|
||||||
filterOptions={filterOptions}
|
filterOptions={filterOptions}
|
||||||
setFilterOptions={setFilterOptions}
|
setFilterOptions={setFilterOptions}
|
||||||
@ -217,7 +241,6 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
|
|||||||
<Comment key={event.id} {...event} />
|
<Comment key={event.id} {...event} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{isLoading && <Spinner />}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user