Show embed view of normal market links in iframes (#254)
This commit is contained in:
parent
a0db1b806a
commit
4c7836abc7
15
web/hooks/use-is-iframe.ts
Normal file
15
web/hooks/use-is-iframe.ts
Normal 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
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user