Répare les liens des iframes

fix #2255
pull/2256/head
Johan Girod 2022-08-29 18:46:58 +02:00
parent c914887405
commit 28ddd61d8d
5 changed files with 11 additions and 8 deletions

View File

@ -5,9 +5,7 @@ export function useIframeResizer() {
// The code below communicate with the iframe.js script on a host site
// to automatically resize the iframe when its inner content height
// change.
if (!window.location.search.includes('iframe')) {
return
}
const minHeight = 700 // Also used in iframe.js
const observer = new ResizeObserver(([entry]) => {
const value = Math.max(minHeight, entry.contentRect.height)

View File

@ -25,7 +25,7 @@ export default function Iframes() {
s.iframePath && (
<Route
key={s.iframePath}
path={s.iframePath + '/*'}
path={'/' + encodeURI(s.iframePath) + '/*'}
element={
<>
<Helmet>

View File

@ -16,7 +16,7 @@ export default function ÉconomieCollaborative() {
const iframePath =
useSimulatorsData()['économie-collaborative'].iframePath ?? ''
const indexPath = useIsEmbedded()
? `/iframes/${iframePath}`
? encodeURI(`/iframes/${iframePath}`)
: économieCollaborative.index
return (

View File

@ -171,7 +171,8 @@ export function SimulateurCard({
<SmallCard
icon={<Emoji emoji={icône} />}
to={{
pathname: (isIframe && `/iframes/${iframePath ?? ''}`) || path,
pathname:
(isIframe && `/iframes/${encodeURI(iframePath ?? '')}`) || path,
}}
state={fromGérer ? { fromGérer: true } : { fromSimulateurs: true }}
title={

View File

@ -59,13 +59,17 @@ function IntegrationCustomizer() {
''
const iframeRef = useRef<HTMLIFrameElement>(null)
const iframeSrc = useHref(`/iframes/${currentIframePath}?iframe`)
const iframeSrc = useHref(`/iframes/${currentIframePath}`)
useEffect(() => {
window.addEventListener(
'message',
function (evt: MessageEvent<{ kind: string; value: string }>) {
if (iframeRef.current && evt.data.kind === 'resize-height') {
if (
iframeRef.current &&
evt.data.kind === 'resize-height' &&
iframeRef.current.contentDocument?.readyState === 'complete'
) {
iframeRef.current.style.height = evt.data.value + 'px'
}
}