Skip to content

Commit

Permalink
Move answer listening down to answers component
Browse files Browse the repository at this point in the history
  • Loading branch information
sipec committed Jun 7, 2024
1 parent 49d3514 commit d365c65
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 18 deletions.
5 changes: 4 additions & 1 deletion web/components/answers/answers-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { formatTime } from 'web/lib/util/time'
import { shortenedFromNow } from 'web/lib/util/shortenedFromNow'
import { getBets } from 'common/supabase/bets'
import { db } from 'web/lib/supabase/db'
import { useAnswersCpmm } from 'web/hooks/use-answers'

export const SHOW_LIMIT_ORDER_CHARTS_KEY = 'SHOW_LIMIT_ORDER_CHARTS_KEY'
const MAX_DEFAULT_ANSWERS = 20
Expand Down Expand Up @@ -115,7 +116,9 @@ export function AnswersPanel(props: {

const isMultipleChoice = outcomeType === 'MULTIPLE_CHOICE'

const answers = contract.answers
const allAnswers = useAnswersCpmm(contract.id) ?? contract.answers

const answers = allAnswers
.filter((a) => isMultipleChoice || ('number' in a && a.number !== 0))
.map((a) => ({
...a,
Expand Down
5 changes: 3 additions & 2 deletions web/components/answers/binary-multi-answers-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import { BuyPanelBody } from 'web/components/bet/bet-panel'
import { VERSUS_COLORS, getVersusColor } from '../charts/contract/choice'
import { useUser } from 'web/hooks/use-user'
import { PencilIcon } from '@heroicons/react/solid'
import { useAnswersCpmm } from 'web/hooks/use-answers'

export function BinaryMultiAnswersPanel(props: {
contract: CPMMMultiContract
answers: Answer[]
feedReason?: string
}) {
const { feedReason, contract, answers } = props
const { feedReason, contract } = props
const answers = useAnswersCpmm(contract.id) ?? contract.answers

const [colorLeft, colorRight] = answers.map(
(a, i) => a.color ?? VERSUS_COLORS[i]
Expand Down
2 changes: 1 addition & 1 deletion web/components/bet/bet-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function MultiBetDialog(props: {
defaultSort,
'answer-sort' + contract.id
)

const isBinaryMC = isBinaryMulti(contract)
return (
<Modal
Expand All @@ -96,7 +97,6 @@ export function MultiBetDialog(props: {
{isBinaryMC ? (
<BinaryMultiAnswersPanel
contract={contract as CPMMMultiContract}
answers={contract.answers}
/>
) : (
<AnswersPanel
Expand Down
10 changes: 2 additions & 8 deletions web/components/contract/contract-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
MultiNumericDistributionChart,
NumericBetPanel,
} from 'web/components/answers/numeric-bet-panel'
import { useAnswersCpmm } from 'web/hooks/use-answers'
import { getAutoBountyPayoutPerHour } from 'common/bounty'
import { NEW_GRAPH_COLOR } from 'common/multi-numeric'
import { FaChartArea } from 'react-icons/fa'
Expand All @@ -86,7 +85,6 @@ import { useIsClient } from 'web/hooks/use-is-client'
export const ContractOverview = memo(
(props: {
contract: Contract
answers: Answer[] | undefined
betPoints: HistoryPoint<Partial<Bet>>[] | MultiPoints
showResolver: boolean
resolutionRating?: ReactNode
Expand All @@ -97,7 +95,6 @@ export const ContractOverview = memo(
const {
betPoints,
contract,
answers,
showResolver,
resolutionRating,
setShowResolver,
Expand Down Expand Up @@ -142,7 +139,6 @@ export const ContractOverview = memo(
return (
<ChoiceOverview
contract={contract}
answers={answers ?? []}
points={betPoints as any}
showResolver={showResolver}
setShowResolver={setShowResolver}
Expand Down Expand Up @@ -493,7 +489,6 @@ const ChartAnnotation = (props: {
const ChoiceOverview = (props: {
points: MultiPoints
contract: MultiContract
answers: Answer[]
showResolver: boolean
resolutionRating?: ReactNode
setShowResolver: (show: boolean) => void
Expand Down Expand Up @@ -929,7 +924,7 @@ const BinaryChoiceOverview = (props: {
) : (
<>
{resolutionRating}
<BinaryMultiAnswersPanel contract={contract} answers={answers} />
<BinaryMultiAnswersPanel contract={contract} />
{tradingAllowed(contract) && (
<UserBetsSummary
className="border-ink-200 !mb-2 mt-2 "
Expand All @@ -946,7 +941,6 @@ const BinaryChoiceOverview = (props: {
export const SimpleMultiOverview = (props: { contract: CPMMMultiContract }) => {
const { contract } = props
const user = useUser()
const answers = useAnswersCpmm(contract.id) ?? contract.answers
const defaultSort = getDefaultSort(contract)

const [sort, setSort] = usePersistentInMemoryState<MultiSort>(
Expand All @@ -973,7 +967,7 @@ export const SimpleMultiOverview = (props: { contract: CPMMMultiContract }) => {
</Row>

<AnswersPanel
contract={{ ...contract, answers }}
contract={contract}
selectedAnswerIds={[]}
sort={sort}
setSort={setSort}
Expand Down
1 change: 0 additions & 1 deletion web/components/contract/feed-contract-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ export function FeedContractCard(props: {
contract.outcomeType !== 'NUMBER' && (
<BinaryMultiAnswersPanel
contract={contract}
answers={contract.answers}
feedReason={feedReason}
/>
)}
Expand Down
5 changes: 1 addition & 4 deletions web/components/dashboard/horizontal-dashboard-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ export function HorizontalDashboardCard(props: {
{isBinaryMc &&
contract.mechanism === 'cpmm-multi-1' &&
contract.outcomeType !== 'NUMBER' && (
<BinaryMultiAnswersPanel
contract={contract}
answers={contract.answers}
/>
<BinaryMultiAnswersPanel contract={contract} />
)}

{isBinaryCpmm && (showGraph || !ignore) && (
Expand Down
1 change: 0 additions & 1 deletion web/pages/[username]/[contractSlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ export function ContractPageContent(props: ContractParams) {
</div>
<ContractOverview
contract={contract}
answers={answers}
betPoints={betPoints as any}
showResolver={showResolver}
resolutionRating={
Expand Down

0 comments on commit d365c65

Please sign in to comment.