update iframe rule
This commit is contained in:
parent
3e4d345207
commit
3a58aa693a
71
app/components/responsive-iframe.tsx
Normal file
71
app/components/responsive-iframe.tsx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
|
interface ResponsiveIframeProps {
|
||||||
|
src: string;
|
||||||
|
className?: string;
|
||||||
|
allow?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ResponsiveIframe({ src, className = '', allow }: ResponsiveIframeProps) {
|
||||||
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const iframe = iframeRef.current;
|
||||||
|
if (!iframe) return;
|
||||||
|
|
||||||
|
const calculateHeight = () => {
|
||||||
|
const pageY = (elem: HTMLElement): number => {
|
||||||
|
return elem.offsetParent ?
|
||||||
|
(elem.offsetTop + pageY(elem.offsetParent as HTMLElement)) :
|
||||||
|
elem.offsetTop;
|
||||||
|
};
|
||||||
|
|
||||||
|
const height = document.documentElement.clientHeight;
|
||||||
|
const iframeY = pageY(iframe);
|
||||||
|
const newHeight = Math.max(0, height - iframeY);
|
||||||
|
iframe.style.height = `${newHeight}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleHashChange = () => {
|
||||||
|
if (window.location.hash && window.location.hash.length) {
|
||||||
|
const iframeURL = new URL(iframe.src);
|
||||||
|
iframeURL.hash = window.location.hash;
|
||||||
|
iframe.src = iframeURL.toString();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initial setup
|
||||||
|
calculateHeight();
|
||||||
|
handleHashChange();
|
||||||
|
|
||||||
|
// Event listeners
|
||||||
|
window.addEventListener('resize', calculateHeight);
|
||||||
|
window.addEventListener('hashchange', handleHashChange);
|
||||||
|
iframe.addEventListener('load', calculateHeight);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('resize', calculateHeight);
|
||||||
|
window.removeEventListener('hashchange', handleHashChange);
|
||||||
|
iframe.removeEventListener('load', calculateHeight);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<iframe
|
||||||
|
ref={iframeRef}
|
||||||
|
id="myFrame"
|
||||||
|
src={src}
|
||||||
|
className={`w-full border-none ${className}`}
|
||||||
|
style={{
|
||||||
|
display: 'block',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%'
|
||||||
|
}}
|
||||||
|
allow={allow}
|
||||||
|
allowFullScreen
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import { getServerSession } from "next-auth/next";
|
import { getServerSession } from "next-auth/next";
|
||||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { ResponsiveIframe } from "@/app/components/responsive-iframe";
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
@ -11,15 +12,10 @@ export default async function Page() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="w-full h-screen bg-black">
|
<main className="w-full h-screen bg-black">
|
||||||
<div className="w-full h-full pt-12">
|
<div className="w-full h-full">
|
||||||
<iframe
|
<ResponsiveIframe
|
||||||
src={process.env.NEXT_PUBLIC_IFRAME_ARTLAB_URL}
|
src={process.env.NEXT_PUBLIC_IFRAME_ARTLAB_URL || ''}
|
||||||
className="w-full h-full border-none"
|
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||||
style={{
|
|
||||||
marginTop: '-64px'
|
|
||||||
}}
|
|
||||||
allowFullScreen
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { getServerSession } from "next-auth/next";
|
import { getServerSession } from "next-auth/next";
|
||||||
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { ResponsiveIframe } from "@/app/components/responsive-iframe";
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
@ -11,12 +12,10 @@ export default async function Page() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="w-full h-screen bg-black">
|
<main className="w-full h-screen bg-black">
|
||||||
<div className="w-full h-full pt-16">
|
<div className="w-full h-full">
|
||||||
<iframe
|
<ResponsiveIframe
|
||||||
src="https://agilite.slm-lab.net/oidc/login"
|
src={process.env.NEXT_PUBLIC_IFRAME_FLOW_URL || ''}
|
||||||
className="w-full h-full border-none"
|
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||||
allowFullScreen
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user