2022-04-09 23:10:58 +00:00
|
|
|
import _ from 'lodash'
|
2022-04-28 17:28:52 +00:00
|
|
|
import { useState, useEffect } from 'react'
|
2022-04-09 23:10:58 +00:00
|
|
|
import { Bet } from '../../common/bet'
|
|
|
|
import { Comment } from '../../common/comment'
|
|
|
|
import { Contract } from '../../common/contract'
|
2022-04-21 06:00:08 +00:00
|
|
|
import { useTimeSinceFirstRender } from './use-time-since-first-render'
|
|
|
|
import { trackLatency } from '../lib/firebase/tracking'
|
2022-04-29 19:25:38 +00:00
|
|
|
import { User } from '../../common/user'
|
|
|
|
import { getUserFeed } from '../lib/firebase/users'
|
2022-04-09 23:10:58 +00:00
|
|
|
|
2022-04-29 19:25:38 +00:00
|
|
|
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[]
|
|
|
|
}[]
|
|
|
|
>()
|
2022-04-09 23:10:58 +00:00
|
|
|
|
2022-04-21 06:00:08 +00:00
|
|
|
const getTime = useTimeSinceFirstRender()
|
|
|
|
|
2022-04-09 23:10:58 +00:00
|
|
|
useEffect(() => {
|
2022-04-29 19:25:38 +00:00
|
|
|
if (user) {
|
|
|
|
getUserFeed(user.id).then((feed) => {
|
|
|
|
setFeed(feed)
|
2022-04-09 23:10:58 +00:00
|
|
|
|
2022-04-29 19:25:38 +00:00
|
|
|
trackLatency('feed', getTime())
|
|
|
|
console.log('feed load time', getTime())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, [user, getTime])
|
2022-04-09 23:10:58 +00:00
|
|
|
|
2022-04-28 17:28:52 +00:00
|
|
|
return feed
|
2022-04-09 23:10:58 +00:00
|
|
|
}
|