manifold/web/hooks/use-comments.ts
Austin Chen 5b431226d4
Show all recent activity on a central feed (#24)
* Tracks all market activity on a single page

* Support both global and per-contract feeds

* UI tweaks

* Include contract description in activity feed

* Show activity feed on Create page
2022-01-11 11:56:26 -05:00

23 lines
622 B
TypeScript

import { useEffect, useState } from 'react'
import {
Comment,
listenForComments,
listenForRecentComments,
} from '../lib/firebase/comments'
export const useComments = (contractId: string) => {
const [comments, setComments] = useState<Comment[] | 'loading'>('loading')
useEffect(() => {
if (contractId) return listenForComments(contractId, setComments)
}, [contractId])
return comments
}
export const useRecentComments = () => {
const [recentComments, setRecentComments] = useState<Comment[] | undefined>()
useEffect(() => listenForRecentComments(setRecentComments), [])
return recentComments
}