(null);
const [isMobile, setIsMobile] = useState(false);
const [isIOS, setIsIOS] = useState(false);
const [isPDF, setIsPDF] = useState(false);
useEffect(() => {
// Detect mobile and iOS
const userAgent = navigator.userAgent.toLowerCase();
setIsMobile(
/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(
userAgent,
),
);
setIsIOS(/iphone|ipad|ipod/i.test(userAgent));
// Try to detect if file is PDF from extension
setIsPDF(allegato.toLowerCase().endsWith(".pdf"));
}, [allegato]);
const handleIframeLoad = () => {
if (if_ref.current?.contentWindow) {
// For images
const img = if_ref.current.contentWindow.document.querySelector("img");
if (img) {
img.style.width = "100%";
img.style.height = "100%";
img.style.objectFit = "contain";
}
}
};
useEffect(() => {
async function set() {
const token = await getToken();
setToken(token);
}
set().catch((e) => console.error(e));
}, []);
if (!token) return ;
const requestUrl = `/go-api/storage/get/${allegato}?token=${String(token)}`;
// For PDF on iOS, provide download link instead
if (isPDF && (isIOS || isMobile)) {
return (
);
}
return (
{/** biome-ignore lint/a11y/noNoninteractiveElementInteractions: */}
);
};