2022-01-04 07:21:14 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
|
|
|
Comment,
|
|
|
|
listenForComments,
|
|
|
|
listenForRecentComments,
|
|
|
|
} from '../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(() => {
|
|
|
|
if (contractId) return listenForComments(contractId, setComments)
|
|
|
|
}, [contractId])
|
|
|
|
|
|
|
|
return comments
|
|
|
|
}
|
2022-01-11 16:56:26 +00:00
|
|
|
|
|
|
|
export const useRecentComments = () => {
|
|
|
|
const [recentComments, setRecentComments] = useState<Comment[] | undefined>()
|
|
|
|
useEffect(() => listenForRecentComments(setRecentComments), [])
|
|
|
|
return recentComments
|
|
|
|
}
|