Show creator avatar in feed

This commit is contained in:
Austin Chen 2022-01-19 02:33:46 -05:00
parent b963cc2fe2
commit 78c461b26c
2 changed files with 36 additions and 15 deletions

View File

@ -5,7 +5,7 @@ export type Contract = {
creatorId: string creatorId: string
creatorName: string creatorName: string
creatorUsername: string creatorUsername: string
creatorAvatarUrl?: string // Start requiring after Mar 01, 2022 creatorAvatarUrl?: string // Start requiring after 2022-03-01
question: string question: string
description: string // More info about what the contract is about description: string // More info about what the contract is about

View File

@ -1,5 +1,5 @@
// From https://tailwindui.com/components/application-ui/lists/feeds // From https://tailwindui.com/components/application-ui/lists/feeds
import { useState } from 'react' import { ReactChild, useState } from 'react'
import _ from 'lodash' import _ from 'lodash'
import { import {
BanIcon, BanIcon,
@ -40,6 +40,27 @@ import { Comment, mapCommentsByBetId } from '../lib/firebase/comments'
import { JoinSpans } from './join-spans' import { JoinSpans } from './join-spans'
import Textarea from 'react-expanding-textarea' import Textarea from 'react-expanding-textarea'
function AvatarWithIcon(props: {
username: string
avatarUrl: string
children: ReactChild
}) {
const { username, avatarUrl, children } = props
return (
<SiteLink className="relative" href={`/${username}`}>
<img
className="h-10 w-10 rounded-full bg-gray-400 flex items-center justify-center ring-8 ring-gray-50"
src={avatarUrl}
alt=""
/>
<span className="absolute -bottom-3 -right-2 bg-gray-50 rounded-tl px-0.5 py-px">
{children}
</span>
</SiteLink>
)
}
function FeedComment(props: { activityItem: any }) { function FeedComment(props: { activityItem: any }) {
const { activityItem } = props const { activityItem } = props
const { person, text, amount, outcome, createdTime } = activityItem const { person, text, amount, outcome, createdTime } = activityItem
@ -49,17 +70,9 @@ function FeedComment(props: { activityItem: any }) {
return ( return (
<> <>
<SiteLink className="relative" href={`/${person.username}`}> <AvatarWithIcon username={person.username} avatarUrl={person.avatarUrl}>
<img
className="h-10 w-10 rounded-full bg-gray-400 flex items-center justify-center ring-8 ring-gray-50"
src={person.avatarUrl}
alt=""
/>
<span className="absolute -bottom-3 -right-2 bg-gray-50 rounded-tl px-0.5 py-px">
<ChatAltIcon className="h-5 w-5 text-gray-400" aria-hidden="true" /> <ChatAltIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
</span> </AvatarWithIcon>
</SiteLink>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<div> <div>
<p className="mt-0.5 text-sm text-gray-500"> <p className="mt-0.5 text-sm text-gray-500">
@ -246,13 +259,21 @@ function FeedQuestion(props: { contract: Contract }) {
return ( return (
<> <>
<div> {contract.creatorAvatarUrl ? (
<AvatarWithIcon
username={contract.creatorUsername}
avatarUrl={contract.creatorAvatarUrl}
>
<StarIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
</AvatarWithIcon>
) : (
// TODO: After 2022-03-01, can just assume that all contracts have an avatarUrl
<div className="relative px-1"> <div className="relative px-1">
<div className="h-8 w-8 bg-gray-200 rounded-full ring-8 ring-gray-50 flex items-center justify-center"> <div className="h-8 w-8 bg-gray-200 rounded-full ring-8 ring-gray-50 flex items-center justify-center">
<StarIcon className="h-5 w-5 text-gray-500" aria-hidden="true" /> <StarIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
</div> </div>
</div> </div>
</div> )}
<div className="min-w-0 flex-1 py-1.5"> <div className="min-w-0 flex-1 py-1.5">
<div className="text-sm text-gray-500 mb-2"> <div className="text-sm text-gray-500 mb-2">
<UserLink <UserLink