2022-01-04 07:21:14 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-08-19 08:06:40 +00:00
|
|
|
import { Comment, ContractComment, GroupComment } from 'common/comment'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
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-08-19 08:06:40 +00:00
|
|
|
const [comments, setComments] = useState<ContractComment[] | 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) => {
|
2022-08-19 08:06:40 +00:00
|
|
|
const [comments, setComments] = useState<GroupComment[] | undefined>()
|
2022-06-24 17:16:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|