Tidying some feed code up (#818)
* Clean up some markup & dead code * Order comments in Firestore instead of on client * Order bets in Firestore instead of on client * Make indexes file up to date with production
This commit is contained in:
parent
40f1c09002
commit
7dddff52b8
|
@ -26,9 +26,55 @@
|
||||||
"collectionGroup": "bets",
|
"collectionGroup": "bets",
|
||||||
"queryScope": "COLLECTION_GROUP",
|
"queryScope": "COLLECTION_GROUP",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "isFilled",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "userId",
|
"fieldPath": "userId",
|
||||||
"order": "ASCENDING"
|
"order": "ASCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "bets",
|
||||||
|
"queryScope": "COLLECTION_GROUP",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "userId",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdTime",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "bets",
|
||||||
|
"queryScope": "COLLECTION",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "isCancelled",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isFilled",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdTime",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "challenges",
|
||||||
|
"queryScope": "COLLECTION_GROUP",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "creatorId",
|
||||||
|
"order": "ASCENDING"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "createdTime",
|
"fieldPath": "createdTime",
|
||||||
|
@ -54,6 +100,34 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "comments",
|
||||||
|
"queryScope": "COLLECTION_GROUP",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "userId",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdTime",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "comments",
|
||||||
|
"queryScope": "COLLECTION_GROUP",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "userId",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "createdTime",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"collectionGroup": "contracts",
|
"collectionGroup": "contracts",
|
||||||
"queryScope": "COLLECTION",
|
"queryScope": "COLLECTION",
|
||||||
|
@ -82,6 +156,42 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "contracts",
|
||||||
|
"queryScope": "COLLECTION",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "creatorId",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isResolved",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "popularityScore",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "contracts",
|
||||||
|
"queryScope": "COLLECTION",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "groupSlugs",
|
||||||
|
"arrayConfig": "CONTAINS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "isResolved",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "popularityScore",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"collectionGroup": "contracts",
|
"collectionGroup": "contracts",
|
||||||
"queryScope": "COLLECTION",
|
"queryScope": "COLLECTION",
|
||||||
|
@ -128,6 +238,46 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "contracts",
|
||||||
|
"queryScope": "COLLECTION",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "isResolved",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "visibility",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "closeTime",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "popularityScore",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collectionGroup": "contracts",
|
||||||
|
"queryScope": "COLLECTION",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "isResolved",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "visibility",
|
||||||
|
"order": "ASCENDING"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "popularityScore",
|
||||||
|
"order": "DESCENDING"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"collectionGroup": "contracts",
|
"collectionGroup": "contracts",
|
||||||
"queryScope": "COLLECTION",
|
"queryScope": "COLLECTION",
|
||||||
|
|
|
@ -126,7 +126,7 @@ export const ContractOverview = (props: {
|
||||||
</Col>
|
</Col>
|
||||||
<div className={'my-1 md:my-2'}></div>
|
<div className={'my-1 md:my-2'}></div>
|
||||||
{(isBinary || isPseudoNumeric) && (
|
{(isBinary || isPseudoNumeric) && (
|
||||||
<ContractProbGraph contract={contract} bets={bets} />
|
<ContractProbGraph contract={contract} bets={[...bets].reverse()} />
|
||||||
)}{' '}
|
)}{' '}
|
||||||
{(outcomeType === 'FREE_RESPONSE' ||
|
{(outcomeType === 'FREE_RESPONSE' ||
|
||||||
outcomeType === 'MULTIPLE_CHOICE') && (
|
outcomeType === 'MULTIPLE_CHOICE') && (
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import clsx from 'clsx'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { User } from 'common/user'
|
import { User } from 'common/user'
|
||||||
import { useUser, useUserById } from 'web/hooks/use-user'
|
import { useUser, useUserById } from 'web/hooks/use-user'
|
||||||
|
@ -24,26 +25,23 @@ export function FeedLiquidity(props: {
|
||||||
const isSelf = user?.id === userId
|
const isSelf = user?.id === userId
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Row className="flex w-full gap-2 pt-3">
|
||||||
<Row className="flex w-full gap-2 pt-3">
|
{isSelf ? (
|
||||||
{isSelf ? (
|
<Avatar avatarUrl={user.avatarUrl} username={user.username} />
|
||||||
<Avatar avatarUrl={user.avatarUrl} username={user.username} />
|
) : bettor ? (
|
||||||
) : bettor ? (
|
<Avatar avatarUrl={bettor.avatarUrl} username={bettor.username} />
|
||||||
<Avatar avatarUrl={bettor.avatarUrl} username={bettor.username} />
|
) : (
|
||||||
) : (
|
<div className="relative px-1">
|
||||||
<div className="relative px-1">
|
<EmptyAvatar />
|
||||||
<EmptyAvatar />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className={'min-w-0 flex-1 py-1.5'}>
|
|
||||||
<LiquidityStatusText
|
|
||||||
liquidity={liquidity}
|
|
||||||
isSelf={isSelf}
|
|
||||||
bettor={bettor}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Row>
|
)}
|
||||||
</>
|
<LiquidityStatusText
|
||||||
|
liquidity={liquidity}
|
||||||
|
isSelf={isSelf}
|
||||||
|
bettor={bettor}
|
||||||
|
className={'flex-1'}
|
||||||
|
/>
|
||||||
|
</Row>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,8 +49,9 @@ export function LiquidityStatusText(props: {
|
||||||
liquidity: LiquidityProvision
|
liquidity: LiquidityProvision
|
||||||
isSelf: boolean
|
isSelf: boolean
|
||||||
bettor?: User
|
bettor?: User
|
||||||
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { liquidity, bettor, isSelf } = props
|
const { liquidity, bettor, isSelf, className } = props
|
||||||
const { amount, createdTime } = liquidity
|
const { amount, createdTime } = liquidity
|
||||||
|
|
||||||
// TODO: Withdrawn liquidity will never be shown, since liquidity amounts currently are zeroed out upon withdrawal.
|
// TODO: Withdrawn liquidity will never be shown, since liquidity amounts currently are zeroed out upon withdrawal.
|
||||||
|
@ -60,7 +59,7 @@ export function LiquidityStatusText(props: {
|
||||||
const money = formatMoney(Math.abs(amount))
|
const money = formatMoney(Math.abs(amount))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="text-sm text-gray-500">
|
<div className={clsx(className, 'text-sm text-gray-500')}>
|
||||||
{bettor ? (
|
{bettor ? (
|
||||||
<UserLink name={bettor.name} username={bettor.username} />
|
<UserLink name={bettor.name} username={bettor.username} />
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -24,11 +24,10 @@ function shortenName(name: string) {
|
||||||
export function UserLink(props: {
|
export function UserLink(props: {
|
||||||
name: string
|
name: string
|
||||||
username: string
|
username: string
|
||||||
showUsername?: boolean
|
|
||||||
className?: string
|
className?: string
|
||||||
short?: boolean
|
short?: boolean
|
||||||
}) {
|
}) {
|
||||||
const { name, username, showUsername, className, short } = props
|
const { name, username, className, short } = props
|
||||||
const shortName = short ? shortenName(name) : name
|
const shortName = short ? shortenName(name) : name
|
||||||
return (
|
return (
|
||||||
<SiteLink
|
<SiteLink
|
||||||
|
@ -36,7 +35,6 @@ export function UserLink(props: {
|
||||||
className={clsx('z-10 truncate', className)}
|
className={clsx('z-10 truncate', className)}
|
||||||
>
|
>
|
||||||
{shortName}
|
{shortName}
|
||||||
{showUsername && ` (@${username})`}
|
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,9 @@ function getBetsCollection(contractId: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listAllBets(contractId: string) {
|
export async function listAllBets(contractId: string) {
|
||||||
const bets = await getValues<Bet>(getBetsCollection(contractId))
|
return await getValues<Bet>(
|
||||||
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
query(getBetsCollection(contractId), orderBy('createdTime', 'desc'))
|
||||||
return bets
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
||||||
|
@ -64,10 +64,10 @@ export function listenForBets(
|
||||||
contractId: string,
|
contractId: string,
|
||||||
setBets: (bets: Bet[]) => void
|
setBets: (bets: Bet[]) => void
|
||||||
) {
|
) {
|
||||||
return listenForValues<Bet>(getBetsCollection(contractId), (bets) => {
|
return listenForValues<Bet>(
|
||||||
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
query(getBetsCollection(contractId), orderBy('createdTime', 'desc')),
|
||||||
setBets(bets)
|
setBets
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserBets(
|
export async function getUserBets(
|
||||||
|
@ -147,12 +147,10 @@ export function listenForUserContractBets(
|
||||||
) {
|
) {
|
||||||
const betsQuery = query(
|
const betsQuery = query(
|
||||||
collection(db, 'contracts', contractId, 'bets'),
|
collection(db, 'contracts', contractId, 'bets'),
|
||||||
where('userId', '==', userId)
|
where('userId', '==', userId),
|
||||||
|
orderBy('createdTime', 'desc')
|
||||||
)
|
)
|
||||||
return listenForValues<Bet>(betsQuery, (bets) => {
|
return listenForValues<Bet>(betsQuery, setBets)
|
||||||
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
|
||||||
setBets(bets)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listenForUnfilledBets(
|
export function listenForUnfilledBets(
|
||||||
|
@ -162,12 +160,10 @@ export function listenForUnfilledBets(
|
||||||
const betsQuery = query(
|
const betsQuery = query(
|
||||||
collection(db, 'contracts', contractId, 'bets'),
|
collection(db, 'contracts', contractId, 'bets'),
|
||||||
where('isFilled', '==', false),
|
where('isFilled', '==', false),
|
||||||
where('isCancelled', '==', false)
|
where('isCancelled', '==', false),
|
||||||
|
orderBy('createdTime', 'desc')
|
||||||
)
|
)
|
||||||
return listenForValues<LimitBet>(betsQuery, (bets) => {
|
return listenForValues<LimitBet>(betsQuery, setBets)
|
||||||
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
|
||||||
setBets(bets)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withoutAnteBets(contract: Contract, bets?: Bet[]) {
|
export function withoutAnteBets(contract: Contract, bets?: Bet[]) {
|
||||||
|
|
|
@ -92,17 +92,15 @@ function getCommentsOnGroupCollection(groupId: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listAllComments(contractId: string) {
|
export async function listAllComments(contractId: string) {
|
||||||
const comments = await getValues<Comment>(getCommentsCollection(contractId))
|
return await getValues<Comment>(
|
||||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
query(getCommentsCollection(contractId), orderBy('createdTime', 'desc'))
|
||||||
return comments
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listAllCommentsOnGroup(groupId: string) {
|
export async function listAllCommentsOnGroup(groupId: string) {
|
||||||
const comments = await getValues<GroupComment>(
|
return await getValues<GroupComment>(
|
||||||
getCommentsOnGroupCollection(groupId)
|
query(getCommentsOnGroupCollection(groupId), orderBy('createdTime', 'desc'))
|
||||||
)
|
)
|
||||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
|
||||||
return comments
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listenForCommentsOnContract(
|
export function listenForCommentsOnContract(
|
||||||
|
@ -110,23 +108,21 @@ export function listenForCommentsOnContract(
|
||||||
setComments: (comments: ContractComment[]) => void
|
setComments: (comments: ContractComment[]) => void
|
||||||
) {
|
) {
|
||||||
return listenForValues<ContractComment>(
|
return listenForValues<ContractComment>(
|
||||||
getCommentsCollection(contractId),
|
query(getCommentsCollection(contractId), orderBy('createdTime', 'desc')),
|
||||||
(comments) => {
|
setComments
|
||||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
|
||||||
setComments(comments)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listenForCommentsOnGroup(
|
export function listenForCommentsOnGroup(
|
||||||
groupId: string,
|
groupId: string,
|
||||||
setComments: (comments: GroupComment[]) => void
|
setComments: (comments: GroupComment[]) => void
|
||||||
) {
|
) {
|
||||||
return listenForValues<GroupComment>(
|
return listenForValues<GroupComment>(
|
||||||
getCommentsOnGroupCollection(groupId),
|
query(
|
||||||
(comments) => {
|
getCommentsOnGroupCollection(groupId),
|
||||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
orderBy('createdTime', 'desc')
|
||||||
setComments(comments)
|
),
|
||||||
}
|
setComments
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,9 +168,6 @@ export function ContractPageContent(
|
||||||
[bets]
|
[bets]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sort for now to see if bug is fixed.
|
|
||||||
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
|
|
||||||
|
|
||||||
const tips = useTipTxns({ contractId: contract.id })
|
const tips = useTipTxns({ contractId: contract.id })
|
||||||
|
|
||||||
const [showConfetti, setShowConfetti] = useState(false)
|
const [showConfetti, setShowConfetti] = useState(false)
|
||||||
|
|
|
@ -71,8 +71,6 @@ export default function ContractEmbedPage(props: {
|
||||||
const contract = useContractWithPreload(props.contract)
|
const contract = useContractWithPreload(props.contract)
|
||||||
const { bets } = props
|
const { bets } = props
|
||||||
|
|
||||||
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)
|
|
||||||
|
|
||||||
if (!contract) {
|
if (!contract) {
|
||||||
return <Custom404 />
|
return <Custom404 />
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user