manifold/web/hooks/use-comments.ts

33 lines
928 B
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react'
import {
Comment,
listenForCommentsOnContract,
2022-06-24 17:16:37 +00:00
listenForCommentsOnGroup,
listenForRecentComments,
} from 'web/lib/firebase/comments'
export const useComments = (contractId: string) => {
const [comments, setComments] = useState<Comment[] | undefined>()
useEffect(() => {
if (contractId) return listenForCommentsOnContract(contractId, setComments)
}, [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
}
export const useRecentComments = () => {
const [recentComments, setRecentComments] = useState<Comment[] | undefined>()
useEffect(() => listenForRecentComments(setRecentComments), [])
return recentComments
}