manifold/web/hooks/use-algo-feed.ts

35 lines
917 B
TypeScript
Raw Normal View History

import _ from 'lodash'
2022-04-28 17:28:52 +00:00
import { useState, useEffect } from 'react'
import { Bet } from '../../common/bet'
import { Comment } from '../../common/comment'
import { Contract } from '../../common/contract'
import { useTimeSinceFirstRender } from './use-time-since-first-render'
import { trackLatency } from '../lib/firebase/tracking'
import { User } from '../../common/user'
import { getUserFeed } from '../lib/firebase/users'
export const useAlgoFeed = (user: User | null | undefined) => {
2022-04-28 17:28:52 +00:00
const [feed, setFeed] = useState<
{
contract: Contract
recentBets: Bet[]
recentComments: Comment[]
}[]
>()
const getTime = useTimeSinceFirstRender()
useEffect(() => {
if (user) {
getUserFeed(user.id).then((feed) => {
setFeed(feed)
trackLatency('feed', getTime())
console.log('feed load time', getTime())
})
}
}, [user, getTime])
2022-04-28 17:28:52 +00:00
return feed
}