2022-01-04 07:21:14 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
|
|
|
Comment,
|
2022-06-22 16:35:50 +00:00
|
|
|
listenForCommentsOnContract,
|
2022-06-24 17:16:37 +00:00
|
|
|
listenForCommentsOnGroup,
|
2022-01-11 16:56:26 +00:00
|
|
|
listenForRecentComments,
|
2022-05-09 13:04:36 +00:00
|
|
|
} from 'web/lib/firebase/comments'
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
export const useComments = (contractId: string) => {
|
2022-01-15 00:16:25 +00:00
|
|
|
const [comments, setComments] = useState<Comment[] | undefined>()
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-06-22 16:35:50 +00:00
|
|
|
if (contractId) return listenForCommentsOnContract(contractId, setComments)
|
2022-01-04 07:21:14 +00:00
|
|
|
}, [contractId])
|
|
|
|
|
|
|
|
return comments
|
|
|
|
}
|
2022-06-24 17:16:37 +00:00
|
|
|
export const useCommentsOnGroup = (groupId: string | undefined) => {
|
|
|
|
const [comments, setComments] = useState<Comment[] | undefined>()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (groupId) return listenForCommentsOnGroup(groupId, setComments)
|
|
|
|
}, [groupId])
|
|
|
|
|
|
|
|
return comments
|
|
|
|
}
|
2022-01-11 16:56:26 +00:00
|
|
|
|
|
|
|
export const useRecentComments = () => {
|
|
|
|
const [recentComments, setRecentComments] = useState<Comment[] | undefined>()
|
|
|
|
useEffect(() => listenForRecentComments(setRecentComments), [])
|
|
|
|
return recentComments
|
|
|
|
}
|