06b7e49e98
* Store view counts & last viewed time * Schedule updating user recommendations. Compute using tf-idf. * Update contract's lastBetTime and lastCommentTime on new bets and comments. * Remove contract's lastUpdatedTime * Remove folds activity feed * Implement getFeed cloud function * Hook up client to use getFeed * Script to cache viewCounts and lastViewTime * Batched wait all userRecommendations * Cache view script runs on all users * Update user feed each hour and get feed from cache doc. * Delete view cache script * Update feed script * Tweak feed algorithm * Compute recommendation scores from updateUserFeed * Disable lastViewedScore factor * Update lastCommentTime script * Comment out console.log * Fix timeout issue by calling new cloud functions with part of the work. * Listen for contract updates to feed. * Handle new user: use default feed of top markets this week * Track lastUpdatedTime * Tweak logic of calling cloud functions in batches * Tweak cloud function batching
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import _ from 'lodash'
|
|
|
|
import { Contract } from '../../lib/firebase/contracts'
|
|
import { Comment } from '../../lib/firebase/comments'
|
|
import { Col } from '../layout/col'
|
|
import { Bet } from '../../../common/bet'
|
|
import { useUser } from '../../hooks/use-user'
|
|
import { ContractActivity } from './contract-activity'
|
|
|
|
export function ActivityFeed(props: {
|
|
feed: {
|
|
contract: Contract
|
|
recentBets: Bet[]
|
|
recentComments: Comment[]
|
|
}[]
|
|
mode: 'only-recent' | 'abbreviated' | 'all'
|
|
getContractPath?: (contract: Contract) => string
|
|
}) {
|
|
const { feed, mode, getContractPath } = props
|
|
|
|
const user = useUser()
|
|
|
|
return (
|
|
<FeedContainer
|
|
feed={feed}
|
|
renderItem={({ contract, recentBets, recentComments }) => (
|
|
<ContractActivity
|
|
user={user}
|
|
contract={contract}
|
|
bets={recentBets}
|
|
comments={recentComments}
|
|
mode={mode}
|
|
contractPath={getContractPath ? getContractPath(contract) : undefined}
|
|
/>
|
|
)}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function FeedContainer(props: {
|
|
feed: {
|
|
contract: Contract
|
|
recentBets: Bet[]
|
|
recentComments: Comment[]
|
|
}[]
|
|
renderItem: (item: {
|
|
contract: Contract
|
|
recentBets: Bet[]
|
|
recentComments: Comment[]
|
|
}) => any
|
|
}) {
|
|
const { feed, renderItem } = props
|
|
|
|
return (
|
|
<Col className="items-center">
|
|
<Col className="w-full max-w-3xl">
|
|
<Col className="w-full divide-y divide-gray-300 self-center bg-white">
|
|
{feed.map((item) => (
|
|
<div key={item.contract.id} className="py-6 px-2 sm:px-4">
|
|
{renderItem(item)}
|
|
</div>
|
|
))}
|
|
</Col>
|
|
</Col>
|
|
</Col>
|
|
)
|
|
}
|