Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
add back admin flag for sweepify lol
remove no longer necessary answers data passthrough
  • Loading branch information
sipec committed Nov 27, 2024
1 parent 4ef144b commit 5e3bd62
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 50 deletions.
2 changes: 1 addition & 1 deletion web/components/contract/contract-info-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export function ContractInfoDialog(props: {
{isAdmin || isTrusted ? (
<SuperBanControl userId={playContract.creatorId} />
) : null}
{!playContract.siblingContractId && (
{isAdmin && !playContract.siblingContractId && (
<ConfirmationButton
openModalBtn={{
label: 'Make sweepcash',
Expand Down
7 changes: 0 additions & 7 deletions web/components/contract/contract-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ import { SpiceCoin } from 'web/public/custom-components/spiceCoin'
import { YourTrades } from 'web/pages/[username]/[contractSlug]'
import { useSweepstakes } from '../sweepstakes-provider'
import { useRouter } from 'next/router'
import { buildArray } from 'common/util/array'
import { useLiveAnswers } from 'web/hooks/use-answers'

export function ContractPageContent(props: ContractParams) {
const {
Expand Down Expand Up @@ -106,10 +104,6 @@ export function ContractPageContent(props: ContractParams) {
!isPlay && liveCashContract ? liveCashContract : livePlayContract
const user = useUser()

const manaAnswers = useLiveAnswers(props.contract.id)
const cashAnswers = useLiveAnswers(props.cash?.contract.id)
const answers = buildArray(manaAnswers, cashAnswers)

// Read and set play state from the query if the user hasn't set their preference
useEffect(() => {
if (
Expand Down Expand Up @@ -522,7 +516,6 @@ export function ContractPageContent(props: ContractParams) {
<ContractTabs
mainContract={props.contract}
liveContract={liveContract}
answers={answers}
bets={bets}
totalBets={totalBets}
comments={comments}
Expand Down
2 changes: 0 additions & 2 deletions web/components/contract/contract-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { TRADE_TERM } from 'common/envs/constants'
export function ContractTabs(props: {
mainContract: Contract
liveContract: Contract
answers: Answer[]
bets: Bet[]
comments: ContractComment[]
userPositionsByOutcome: ContractMetricsByOutcome
Expand All @@ -66,7 +65,6 @@ export function ContractTabs(props: {
const {
mainContract,
liveContract,
answers,
comments,
bets,
replyTo,
Expand Down
2 changes: 1 addition & 1 deletion web/components/feed/scored-feed-repost-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function RepostLabel(props: {
if (creatorRepostedTheirComment) {
return (
<Row className="grow-x bg-canvas-100/50 -mx-4 -mt-4 mb-3 rounded-t-lg px-4 pb-1 pt-2">
{header}i''
{header}
{dropdown}
</Row>
)
Expand Down
39 changes: 0 additions & 39 deletions web/hooks/use-answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,3 @@ export function useLiveAnswer(answerId: string | undefined) {

return answer
}

// export function useAnswers(contractId: string | undefined) {

export function useLiveAnswers(contractId: string | undefined) {
const [answers, setAnswers] = useState<Answer[]>([])

useEffect(() => {
if (contractId) {
// TODO: create api
api('market/:contractId/answers', {
contractId,
}).then(setAnswers)
}
}, [contractId])

useApiSubscription({
enabled: contractId != undefined,
topics: [
`contract/${contractId}/new-answer`,
`contract/${contractId}/updated-answers`,
],
onBroadcast: ({ data, topic }) => {
if (topic.endsWith('new-answer')) {
setAnswers((a) => [...a, data.answer as Answer])
} else if (topic.endsWith('updated-answers')) {
const updates = data.answers as (Partial<Answer> & { id: string })[]
setAnswers((a) =>
a.map((a) => {
const u = updates.find((u) => u.id === a.id)
if (!u) return a
return { ...a, ...u }
})
)
}
},
})

return answers
}

0 comments on commit 5e3bd62

Please sign in to comment.