From 3cd72bcc3214d678bc498e070ce8bd63a7baf5a6 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sun, 2 Jan 2022 23:15:35 -0800 Subject: [PATCH] Show all bets in a feed-like manner --- web/components/contract-feed.tsx | 67 ++++++++++++++++++---------- web/components/contract-overview.tsx | 5 +++ 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index e25241d7..b81bc4b7 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -1,6 +1,12 @@ // From https://tailwindui.com/components/application-ui/lists/feeds import { Fragment } from 'react' import { ChatAltIcon, TagIcon, UserCircleIcon } from '@heroicons/react/solid' +import { useBets } from '../hooks/use-bets' +import { Bet } from '../lib/firebase/bets' +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' +import { Contract } from '../lib/firebase/contracts' +dayjs.extend(relativeTime) const activity = [ { @@ -14,10 +20,10 @@ const activity = [ date: '6d ago', }, { - id: 2, - type: 'assignment', - person: { name: 'Hilary Mahy', href: '#' }, - assigned: { name: 'Kristin Watson', href: '#' }, + id: 'hifadsdf', + type: 'bet', + outcome: 'YES', + amount: 30, date: '2d ago', }, { @@ -83,8 +89,9 @@ function FeedComment(props: { activityItem: any }) { ) } -function FeedAssignment(props: { activityItem: any }) { +function FeedBet(props: { activityItem: any }) { const { activityItem } = props + const { amount, outcome, createdTime } = activityItem return ( <>
@@ -99,20 +106,14 @@ function FeedAssignment(props: { activityItem: any }) {
- Someone placed M$ {amount} on{' '} + {outcome}{' '} + - {activityItem.person.name} - {' '} - assigned{' '} - - {activityItem.assigned.name} - {' '} - {activityItem.date} + {dayjs(createdTime).fromNow()} +
@@ -171,14 +172,34 @@ function FeedTags(props: { activityItem: any }) { ) } -export function ContractFeed() { +function toFeedBet(bet: Bet) { + return { + id: bet.id, + type: 'bet', + amount: bet.amount, + outcome: bet.outcome, + createdTime: bet.createdTime, + date: dayjs(bet.createdTime).fromNow(), + } +} + +export function ContractFeed(props: { contract: Contract }) { + const { contract } = props + const { id } = contract + + let bets = useBets(id) + if (bets === 'loading') bets = [] + + // const allItems = [...bets.map(toFeedBet), ...activity] + const allItems = bets.map(toFeedBet) + return (