From 07ce27f20b9105699180be40ed87c654fde340e3 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Mon, 3 Jan 2022 23:21:14 -0800 Subject: [PATCH] Show activity feed on each market & allow comments on your bets (#18) * Copy feed template from TailwindUI * Show all bets in a feed-like manner * Tweak design of individual trades * Allow traders to comment on their bets * Code cleanups * Incorporate contract description into the feed * Support description editing from contract feed * Group together bets placed within 24h * Fix build error * Add a feed item for market resolution * Add a feed item for markets that have closed * Comment on a separate subcollection --- web/components/contract-feed.tsx | 472 +++++++++++++++++++++++++++ web/components/contract-overview.tsx | 89 +---- web/hooks/use-comments.ts | 12 + web/lib/firebase/bets.ts | 1 + web/lib/firebase/comments.ts | 60 ++++ 5 files changed, 551 insertions(+), 83 deletions(-) create mode 100644 web/components/contract-feed.tsx create mode 100644 web/hooks/use-comments.ts create mode 100644 web/lib/firebase/comments.ts diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx new file mode 100644 index 00000000..49671d4c --- /dev/null +++ b/web/components/contract-feed.tsx @@ -0,0 +1,472 @@ +// From https://tailwindui.com/components/application-ui/lists/feeds +import { useState } from 'react' +import { + BanIcon, + ChatAltIcon, + CheckIcon, + LockClosedIcon, + StarIcon, + ThumbDownIcon, + ThumbUpIcon, + UserIcon, + UsersIcon, + XIcon, +} from '@heroicons/react/solid' +import { useBets } from '../hooks/use-bets' +import { Bet } from '../lib/firebase/bets' +import { Comment, mapCommentsByBetId } from '../lib/firebase/comments' +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' +import { OutcomeLabel } from './outcome-label' +import { Contract, setContract } from '../lib/firebase/contracts' +import { useUser } from '../hooks/use-user' +import { Linkify } from './linkify' +import { Row } from './layout/row' +import { createComment } from '../lib/firebase/comments' +import { useComments } from '../hooks/use-comments' +dayjs.extend(relativeTime) + +function FeedComment(props: { activityItem: any }) { + const { activityItem } = props + const { person, text, amount, outcome, createdTime } = activityItem + return ( + <> +
+ + + + +
+
+
+

+ + {person.name} + {' '} + placed M$ {amount} on {' '} + +

+
+
+

+ +

+
+
+ + ) +} + +function Timestamp(props: { time: number }) { + const { time } = props + return ( + + {dayjs(time).fromNow()} + + ) +} + +function FeedBet(props: { activityItem: any }) { + const { activityItem } = props + const { id, contractId, amount, outcome, createdTime } = activityItem + const user = useUser() + const isCreator = user?.id == activityItem.userId + + const [comment, setComment] = useState('') + async function submitComment() { + if (!user || !comment) return + await createComment(contractId, id, comment, user) + } + return ( + <> +
+
+
+
+
+
+
+
+ + {isCreator ? 'You' : 'A trader'} + {' '} + placed M$ {amount} on {' '} + + {isCreator && ( + // Allow user to comment in an textarea if they are the creator +
+