Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/src/pages/Model.page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
/**
* Embeds the PolicyEngine Model overview from Vercel.
* Inherits policyengine.org header/footer via StaticLayout.
*
* The embedded app posts its content height via postMessage so the
* iframe can grow to fit, letting the parent page scroll naturally
* with the footer only visible at the very bottom.
*/
import { useCallback, useEffect, useState } from 'react';
import { useCurrentCountry } from '@/hooks/useCurrentCountry';

export default function ModelPage() {
const countryId = useCurrentCountry();
const embedUrl = `https://policyengine-model.vercel.app?embed&country=${countryId}`;
const [height, setHeight] = useState<number | null>(null);

const handleMessage = useCallback((event: MessageEvent) => {
if (event.data?.type === 'policyengine-model-height') {
setHeight(event.data.height);
}
}, []);

useEffect(() => {
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, [handleMessage]);

return (
<iframe
src={embedUrl}
title="Model overview | PolicyEngine"
style={{
width: '100%',
minHeight: 'calc(100vh - 200px)',
height: height ? `${height}px` : 'calc(100vh - 200px)',
border: 'none',
}}
/>
Expand Down