zack commited on
Commit
664b836
·
1 Parent(s): c2465c6

chore: remove src/components/Nodes/Custom.js 🧹

Browse files
frontend/src/components/Nodes/Custom.js DELETED
@@ -1,99 +0,0 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react"
2
- // import { Handle, Position } from "react-flow-renderer"
3
- import {TbResize} from 'react-icons/tb'
4
- import {BiCube, BiRefresh} from 'react-icons/bi'
5
- import {BsTrash} from 'react-icons/bs'
6
- import {CgLayoutGridSmall} from 'react-icons/cg'
7
- import {useDrag} from '@use-gesture/react'
8
- import { useSpring, animated } from 'react-spring'
9
-
10
- import '../../css/counter.css'
11
-
12
- const MINIMUM_HEIGHT = 600;
13
- const MINIMUM_WIDTH = 540;
14
-
15
- export default function CustomNodeIframe({id, data}){
16
- const [collapsed, setCollapsible] = useState(true)
17
- const [{width, height}, api] = useSpring(() => ({width: MINIMUM_WIDTH, height: MINIMUM_HEIGHT }))
18
- const [sizeAdjuster, setSizeAdjuster] = useState(false)
19
- const [reachable ,setReachable] = useState(false)
20
- const [refresh, setRefresh] = useState(0)
21
- const dragElement = useRef()
22
-
23
- const bind = useDrag((state) => {
24
- const isResizing = (state?.event.target === dragElement.current);
25
- if (isResizing) {
26
- api.set({
27
- width: state.offset[0],
28
- height: state.offset[1],
29
-
30
- });
31
- }
32
- }, {
33
- from: (event) => {
34
- const isResizing = (event.target === dragElement.current);
35
- if (isResizing) {
36
- return [width.get(), height.get()];
37
- }
38
- },
39
- });
40
-
41
- const isFetchable =useCallback(async () => {
42
- return fetch(data.host, {mode: 'no-cors'}).then((res) => {
43
- return true
44
- }).catch((err)=>{
45
- return false
46
- })
47
- }, [data.host])
48
-
49
- useEffect(() => {
50
- const fetched = setInterval(
51
- async () => {
52
- const fetch = await isFetchable()
53
- if (fetch){
54
- setReachable(true)
55
- clearInterval(fetched)
56
- }
57
- },1000)
58
- },[isFetchable])
59
-
60
-
61
- return (
62
- <div className="w-10 h-10">
63
-
64
- <div id={'draggable'}className=" flex w-full h-10 top-0 cursor-pointer" onClick={() => {}}>
65
- <div id={'draggable'} title={collapsed ? "Collaspse Node" : "Expand Node"} className=" flex-none duration-300 cursor-pointer shadow-xl border-2 border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Blue rounded-xl" onClick={() => {setCollapsible((clps) => !clps)}}><CgLayoutGridSmall className="h-full w-full text-white p-1"/></div>
66
-
67
- <div className={` flex ${!collapsed ? '' : 'w-0 hidden'}`}>
68
- <div title="Adjust Node Size" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Violet rounded-xl" onClick={() => {setSizeAdjuster((size) => !size)}}><TbResize className="h-full w-full text-white p-1"/></div>
69
- <a href={data.host} target="_blank" rel="noopener noreferrer"><div title="Gradio Host Site" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Pink rounded-xl"><BiCube className="h-full w-full text-white p-1"/></div></a>
70
- <div title="Delete Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Red rounded-xl" onClick={() => {data.delete([{id}])}}><BsTrash className="h-full w-full text-white p-1"/></div>
71
- <div title="Refresh Node" className="duration-300 cursor-pointer shadow-xl border-2 dark:border-white border-white h-10 w-10 mr-2 -mt-3 bg-Warm-Orange rounded-xl" onClick={() => {setRefresh((old) => old++)}}><BiRefresh className="h-full w-full text-white p-1"/></div>
72
- </div>
73
- </div>
74
-
75
- { !collapsed && reachable && <>
76
- <animated.div className={`border-dashed ${sizeAdjuster ? 'border-4 border-white' : ''} relative top-0 left-0 z-[1000] touch-none shadow-lg rounded-xl`} style={{width, height }} {...bind()}>
77
- <div id="draggable" className={`absolute h-full w-full ${data.colour} shadow-2xl rounded-xl -z-20`}></div>
78
- <iframe id="iframe"
79
- key={refresh}
80
- src={data.host}
81
- title={data.label}
82
- frameBorder="0"
83
- className=" p-[0.6rem] -z-10 h-full w-full ml-auto mr-auto overflow-y-scroll"/>
84
- <div className={` ${sizeAdjuster ? '' : 'hidden'} rounded-full border-2 absolute -bottom-4 -right-4 w-7 h-7 bg-Blue-Royal cursor-nwse-resize touch-none shadow-lg`} ref={dragElement}>
85
- </div>
86
- </animated.div>
87
- </>
88
- }
89
-
90
- { collapsed &&
91
- <div id={`draggable`}
92
- className={` w-[340px] h-[140px] text-white text-md flex flex-col text-center items-center cursor-grab shadow-lg
93
- p-5 px-2 rounded-md break-all -z-20 ${data.colour} hover:opacity-70 duration-300`} onClick={() => setCollapsible(collapsed => !collapsed)}>
94
- <div className="absolute text-6xl opacity-60 z-10 pt-8 ">{data.emoji}</div>
95
- <h2 className={`max-w-full font-sans text-blue-50 leading-tight font-bold text-3xl flex-1 z-20 pt-10`} style={{"textShadow" : "0px 1px 2px rgba(0, 0, 0, 0.25)"}} >{data.label}</h2>
96
- </div >
97
- }
98
- </div>)
99
- }