import React, { useCallback, useEffect, useRef, useState } from "react" /** * Custom hook to check iframe reachability. * @param {string} url - The URL to check for reachability. * @returns {boolean} - True if reachable, false otherwise. */ import {TbResize} from 'react-icons/tb' import {BiCube, BiRefresh} from 'react-icons/bi' import {BsTrash} from 'react-icons/bs' import {CgLayoutGridSmall} from 'react-icons/cg' import {useDrag} from '@use-gesture/react' import { useSpring, animated } from 'react-spring' const MINIMUM_HEIGHT = 600; const MINIMUM_WIDTH = 540; export default function CustomNodeIframe({id, data, handleAddEmbed}){ const [collapsed, setCollapsible] = useState(true) const [{width, height}, api] = useSpring(() => ({width: MINIMUM_WIDTH, height: MINIMUM_HEIGHT })) const [sizeAdjuster, setSizeAdjuster] = useState(false) const [reachable ,setReachable] = useState(false) const [refresh, setRefresh] = useState(0) const dragElement = useRef() const bind = useDrag((state) => { const isResizing = (state?.event.target === dragElement.current); if (isResizing) { api.set({ width: state.offset[0], height: state.offset[1], }); } }, { from: (event) => { const isResizing = (event.target === dragElement.current); if (isResizing) { return [width.get(), height.get()]; } }, }); useEffect(() => { const fetched = setInterval( async () => { setReachable(true) clearInterval(fetched) },1000) },[]) const [iframeUrl, setIframeUrl] = useState(''); const [iframeLabel, setIframeLabel] = useState(''); const handleIframeUrlChange = (e) => { setIframeUrl(e.target.value); }; const handleIframeLabelChange = (e) => { setIframeLabel(e.target.value); }; const addIframeNode = () => { handleAddEmbed({ url: iframeUrl, label: iframeLabel || 'Embedded Content' }); setIframeUrl(''); // Reset the input field after adding setIframeLabel(''); }; return (
) }