Show embed view of normal market links in iframes (#254)

This commit is contained in:
Sinclair Chen 2022-05-19 17:34:08 -07:00 committed by GitHub
parent a0db1b806a
commit 4c7836abc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import { useEffect, useState } from 'react'
function inIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}
export function useIsIframe() {
const [is, setIs] = useState(false)
useEffect(() => setIs(inIframe()), []) // useEffect so this happens client side
return is
}

View File

@ -44,6 +44,8 @@ import { NumericBetPanel } from '../../components/numeric-bet-panel'
import { NumericResolutionPanel } from '../../components/numeric-resolution-panel'
import { FeedComment } from 'web/components/feed/feed-comments'
import { FeedBet } from 'web/components/feed/feed-bets'
import { useIsIframe } from 'web/hooks/use-is-iframe'
import ContractEmbedPage from '../embed/[username]/[contractSlug]'
export const getStaticProps = fromPropz(getStaticPropz)
export async function getStaticPropz(props: {
@ -113,6 +115,11 @@ export function ContractPageContent(props: FirstArgument<typeof ContractPage>) {
setShowConfetti(shouldSeeConfetti)
}, [contract, user])
const inIframe = useIsIframe()
if (inIframe) {
return <ContractEmbedPage {...props} />
}
// Sort for now to see if bug is fixed.
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
bets.sort((bet1, bet2) => bet1.createdTime - bet2.createdTime)