LucaVivona commited on
Commit
e59d3dd
1 Parent(s): bd87444

refactor 🚧

Browse files
frontend/src/components/Modal/importer.js CHANGED
@@ -9,7 +9,7 @@ import {BsSearch} from 'react-icons/bs';
9
  export default function Import(props){
10
  const [tab, setTab] = useState("gradio")
11
  const [subTab, setSubTab] = useState(0)
12
-
13
  return (<div>
14
  <Modal
15
  basic
@@ -19,15 +19,21 @@ export default function Import(props){
19
  >
20
  <div className='w-full shadow-lg rounded-lg'>
21
  <ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-100 rounded-t-lg border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
22
- <li className="" onClick={()=>{setTab("gradio")}}>
 
 
23
  <button id="gradio-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 rounded-tl-lg ${ tab === "gradio" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Gradio className=" w-20 h-10"/></button>
24
  </li>
25
- <li className="" onClick={()=>{setTab("streamlit")}}>
 
 
26
  <button id="services-tab" data-tabs-target="#Streamlit" type="button" role="tab" aria-controls="services" aria-selected="false" className={`inline-block p-4 rounded-tl-lg ${ tab === "streamlit" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Streamlit className=" w-20 h-10"/></button>
27
  </li>
28
  </ul>
29
  <div className='absolute right-5 top-5 z-20 mr-5'
30
- onClick={()=>{props.quitHandeler(false)}}>
 
 
31
  <button type="button"
32
  className=" bg-neutral-300 rounded-2xl p-2 inline-flex items-center justify-center dark:bg-neutral-700 hover:opacity-70 focus:outline-none">
33
  <Exit className=" w-[20px] h-[20px] text-gray-400 dark:text-white"/>
@@ -37,15 +43,19 @@ export default function Import(props){
37
  { tab === "gradio" &&
38
  <div className='w-full bg-white'>
39
  <ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-200 border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
40
- <li className="" onClick={()=>{setSubTab(0)}}>
 
 
41
  <button id="local-sub-tab" data-tabs-target="#local" type="button" role="tab" aria-controls="local-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 0 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Local</button>
42
  </li>
43
- <li className="" onClick={()=>{setSubTab(1)}}>
 
 
44
  <button id="shared-sub-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="shared-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 1 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Shared</button>
45
  </li>
46
  </ul>
47
  {subTab === 0 && <Local/>}
48
- {subTab === 1 && <Shared textHandler={props.textHandler} appendHandler={props.appendHandler} />}
49
 
50
  {props.catch && <div className='p-5'>
51
  <Message floating negative>
@@ -94,12 +104,26 @@ function Shared(props){
94
  const [fetchable, setFetch] = useState(false)
95
 
96
  const isFetchable = async (url) => {
97
- console.log(url)
 
 
 
 
 
 
 
 
 
 
 
98
  fetch(url, {mode : "no-cors"}).then((re) => {
99
  console.log(re)
100
  if(re.url.includes("http://localhost:3000")){
101
  setFetch(false)
102
- } else { setFetch(true) }
 
 
 
103
 
104
  }).catch((err)=>{
105
  setFetch(false)
@@ -143,7 +167,7 @@ function Shared(props){
143
  <Icon className=" text-gray-500 block float-left cursor-pointer mr-2" name="address card"/>
144
  </span>
145
  <input className={`placeholder:italic placeholder:text-slate-400 text-black dark:text-white block bg-transparent w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 pr-3 focus:shadow-xl focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm`}
146
- placeholder={`Name` }
147
  type="text" name="search"
148
  autoComplete='off'
149
  onChange={(e) => {
 
9
  export default function Import(props){
10
  const [tab, setTab] = useState("gradio")
11
  const [subTab, setSubTab] = useState(0)
12
+
13
  return (<div>
14
  <Modal
15
  basic
 
19
  >
20
  <div className='w-full shadow-lg rounded-lg'>
21
  <ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-100 rounded-t-lg border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
22
+ <li className="" onClick={()=>{
23
+ setTab("gradio")
24
+ props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
25
  <button id="gradio-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 rounded-tl-lg ${ tab === "gradio" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Gradio className=" w-20 h-10"/></button>
26
  </li>
27
+ <li className="" onClick={()=>{
28
+ setTab("streamlit")
29
+ props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
30
  <button id="services-tab" data-tabs-target="#Streamlit" type="button" role="tab" aria-controls="services" aria-selected="false" className={`inline-block p-4 rounded-tl-lg ${ tab === "streamlit" ? 'bg-gray-200' : 'hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 focus:bg-gray-700'}`}><Streamlit className=" w-20 h-10"/></button>
31
  </li>
32
  </ul>
33
  <div className='absolute right-5 top-5 z-20 mr-5'
34
+ onClick={()=>{
35
+ props.quitHandeler(false)
36
+ props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
37
  <button type="button"
38
  className=" bg-neutral-300 rounded-2xl p-2 inline-flex items-center justify-center dark:bg-neutral-700 hover:opacity-70 focus:outline-none">
39
  <Exit className=" w-[20px] h-[20px] text-gray-400 dark:text-white"/>
 
43
  { tab === "gradio" &&
44
  <div className='w-full bg-white'>
45
  <ul className="flex flex-wrap text-sm font-medium text-center text-gray-500 bg-gray-200 border-gray-200 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-800" id="defaultTab" data-tabs-toggle="#defaultTabContent" role="tablist">
46
+ <li className="" onClick={()=>{
47
+ setSubTab(0)
48
+ props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
49
  <button id="local-sub-tab" data-tabs-target="#local" type="button" role="tab" aria-controls="local-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 0 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Local</button>
50
  </li>
51
+ <li className="" onClick={()=>{
52
+ setSubTab(1)
53
+ props.catch ? props.handelError(false) : props.handelError(props.catch) }}>
54
  <button id="shared-sub-tab" data-tabs-target="#Gradio" type="button" role="tab" aria-controls="shared-gradio" aria-selected={tab === "gradio" ? "true" : "false"} className={`inline-block p-4 px-6 text-base font-sans font-bold ${subTab === 1 ? 'bg-gray-300' : '' } hover:bg-gray-300 `}>Shared</button>
55
  </li>
56
  </ul>
57
  {subTab === 0 && <Local/>}
58
+ {subTab === 1 && <Shared textHandler={props.textHandler} appendHandler={props.appendHandler} handelError={props.handelError} catch={props.catch}/>}
59
 
60
  {props.catch && <div className='p-5'>
61
  <Message floating negative>
 
104
  const [fetchable, setFetch] = useState(false)
105
 
106
  const isFetchable = async (url) => {
107
+ const pattern = {
108
+ share : /^https?:\/\/*([0-9]{5})*(-gradio)*(.app)?(\/)?$/,
109
+ hugginFace : /^https?:\/\/*(hf.space)\/*(embed)\/*([a-zA-Z0-9+_-]+)\/*([a-zA-Z0-9+_-]+)\/*([+])?(\/)?$/
110
+ }
111
+
112
+ if (!pattern.share.test(url) &&
113
+ !pattern.hugginFace.test(url)){
114
+ setFetch(false)
115
+ return
116
+ }
117
+
118
+
119
  fetch(url, {mode : "no-cors"}).then((re) => {
120
  console.log(re)
121
  if(re.url.includes("http://localhost:3000")){
122
  setFetch(false)
123
+ } else {
124
+ setFetch(true)
125
+ props.catch ? props.handelError(false) : props.handelError(props.catch)
126
+ }
127
 
128
  }).catch((err)=>{
129
  setFetch(false)
 
167
  <Icon className=" text-gray-500 block float-left cursor-pointer mr-2" name="address card"/>
168
  </span>
169
  <input className={`placeholder:italic placeholder:text-slate-400 text-black dark:text-white block bg-transparent w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 pr-3 focus:shadow-xl focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm`}
170
+ placeholder={`Name ( > 20 Characters)` }
171
  type="text" name="search"
172
  autoComplete='off'
173
  onChange={(e) => {
frontend/src/components/Navagation/navbar.js CHANGED
@@ -62,7 +62,9 @@ export default class Navbar extends Component{
62
  hugginFace : /^https?:\/\/*(hf.space)\/*(embed)\/*([a-zA-Z0-9+_-]+)\/*([a-zA-Z0-9+_-]+)\/*([+])?(\/)?$/
63
  }
64
 
65
- if (this.state.menu.findIndex(element => {return element.name.toLowerCase() === this.state.name.toLowerCase() || element.host.includes(this.state.text) }) !== -1 ||
 
 
66
  this.state.text.includes(" ") ||
67
  (!pattern.local.test(this.state.text) &&
68
  !pattern.share.test(this.state.text) &&
@@ -154,6 +156,10 @@ export default class Navbar extends Component{
154
  }
155
  }
156
 
 
 
 
 
157
  /**
158
  * handel navagation open and close function
159
  */
@@ -213,6 +219,7 @@ export default class Navbar extends Component{
213
  quitHandeler={this.handelModal}
214
  textHandler={this.updateText}
215
  appendHandler={this.append_gradio}
 
216
  catch={this.state.error}/>
217
 
218
  <div className=" relative z-10 h-auto overflow-auto pt-4">
@@ -231,7 +238,3 @@ export default class Navbar extends Component{
231
  </div>)
232
  }
233
  }
234
-
235
- /**
236
- *
237
- * **/
 
62
  hugginFace : /^https?:\/\/*(hf.space)\/*(embed)\/*([a-zA-Z0-9+_-]+)\/*([a-zA-Z0-9+_-]+)\/*([+])?(\/)?$/
63
  }
64
 
65
+ if (this.state.name.length > 20 ||
66
+ this.state.text === ""||
67
+ this.state.menu.findIndex(element => {return element.name.toLowerCase() === this.state.name.toLowerCase() || element.host.includes(this.state.text) }) !== -1 ||
68
  this.state.text.includes(" ") ||
69
  (!pattern.local.test(this.state.text) &&
70
  !pattern.share.test(this.state.text) &&
 
156
  }
157
  }
158
 
159
+ handelError = (boolean) => {
160
+ this.setState({'error' : boolean})
161
+ }
162
+
163
  /**
164
  * handel navagation open and close function
165
  */
 
219
  quitHandeler={this.handelModal}
220
  textHandler={this.updateText}
221
  appendHandler={this.append_gradio}
222
+ handelError={this.handelError}
223
  catch={this.state.error}/>
224
 
225
  <div className=" relative z-10 h-auto overflow-auto pt-4">
 
238
  </div>)
239
  }
240
  }
 
 
 
 
frontend/src/components/Nodes/Custom.js CHANGED
@@ -31,11 +31,11 @@ export default class CustomNodeIframe extends React.Component {
31
  }
32
 
33
  handelSelected = () => {
34
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : !this.state.selected, data : this.state.data, width : this.state.width, height : this.state.height, size : this.state.size, iframe : this.state.iframe})
35
  }
36
 
37
  handelSizeState = () => {
38
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : this.state.width, height : this.state.height, size : !this.state.size, iframe : this.state.iframe})
39
  }
40
 
41
  isFetchable = async (host) => {
@@ -57,18 +57,18 @@ export default class CustomNodeIframe extends React.Component {
57
  if(!this.isFetchable(this.state.data.host)){
58
  this.onNodeClick(this.state.id)
59
  } else{
60
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : this.state.width, height : this.state.height, size : this.state.size, iframe : this.state.iframe + 1})
61
  }
62
  }
63
 
64
  handelOnChange(evt, type){
65
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : type === "width" ? parseInt(evt.target.value) : this.state.width, height : type === "height" ? parseInt(evt.target.value) : this.state.height, size : this.state.size, iframe : this.state.iframe })
66
- type === "width" ? this.myRef.current.style.width = `${parseInt(evt.target.value)}px` : this.myRef.current.style.height = `${parseInt(evt.target.value)}px`
67
  }
68
 
69
  handelSize(evt, increment, change){
70
  if (evt === "increment") {
71
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : change === "width" ? this.state.width + increment : this.state.width, height : change === "height" ? this.state.height + increment : this.state.height, size : this.state.size, iframe : this.state.iframe })
72
  change === "width" ? this.myRef.current.style.width = `${this.state.width + increment}px` : this.myRef.current.style.height = `${this.state.height + increment}px`
73
  }
74
 
@@ -95,21 +95,19 @@ export default class CustomNodeIframe extends React.Component {
95
  height = this.original_height + (e.clientY - this.original_mouse_y)
96
  if (width > MINIMUM_WIDTH) {
97
  this.myRef.current.style.width = `${width}px`
98
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : parseInt(width) , height : parseInt(height), size : this.state.size, iframe : this.state.iframe})
99
 
100
  }
101
  if (height > MINIMUM_HEIGHT) {
102
  this.myRef.current.style.height = `${height}px`
103
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : parseInt(width) , height : parseInt(height), size : this.state.size, iframe : this.state.iframe})
104
 
105
  }
106
  }
107
  }
108
 
109
  OnDragEnd = () => {
110
- console.log("end")
111
- this.setState({id : this.state.id, reachable : this.state.reachable, selected : this.state.selected, data : this.state.data, width : parseInt(this.myRef.current.style.width), height : parseInt(this.myRef.current.style.height), size : this.state.size, iframe : this.state.iframe})
112
-
113
  }
114
 
115
  Counter(focus, size){
@@ -160,7 +158,7 @@ export default class CustomNodeIframe extends React.Component {
160
  sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"
161
  ></iframe>
162
  </div>
163
- { this.state.size && <>
164
 
165
  <div id="remove-ghost" className={`absolute select-none -bottom-0 right-0 w-5 h-5border-2 shadow-2xl rounded-xl z-10 cursor-nwse-resize hover:opacity-50 `}
166
  style={{"userDrag": "none"}}
 
31
  }
32
 
33
  handelSelected = () => {
34
+ this.setState({'selected' : !this.state.selected})
35
  }
36
 
37
  handelSizeState = () => {
38
+ this.setState({'size' : !this.state.size})
39
  }
40
 
41
  isFetchable = async (host) => {
 
57
  if(!this.isFetchable(this.state.data.host)){
58
  this.onNodeClick(this.state.id)
59
  } else{
60
+ this.setState({'iframe' : this.state.iframe + 1})
61
  }
62
  }
63
 
64
  handelOnChange(evt, type){
65
+ this.setState({[`${type}`] : parseInt(evt.target.value) })
66
+ type === "width" ? this.myRef.current.style.width = `${parseInt(evt.target.value)}px` : this.myRef.current.style.height = `${parseInt(evt.target.value)}px`
67
  }
68
 
69
  handelSize(evt, increment, change){
70
  if (evt === "increment") {
71
+ this.setState({[`${change}`] : change === "width" ? this.state.width + increment : this.state.height + increment })
72
  change === "width" ? this.myRef.current.style.width = `${this.state.width + increment}px` : this.myRef.current.style.height = `${this.state.height + increment}px`
73
  }
74
 
 
95
  height = this.original_height + (e.clientY - this.original_mouse_y)
96
  if (width > MINIMUM_WIDTH) {
97
  this.myRef.current.style.width = `${width}px`
98
+ this.setState({'width' : parseInt(width) , 'height' : parseInt(height)})
99
 
100
  }
101
  if (height > MINIMUM_HEIGHT) {
102
  this.myRef.current.style.height = `${height}px`
103
+ this.setState({'width' : parseInt(width) , 'height' : parseInt(height)})
104
 
105
  }
106
  }
107
  }
108
 
109
  OnDragEnd = () => {
110
+ this.setState({'width' : parseInt(this.myRef.current.offsetWidth), 'height' : parseInt(this.myRef.current.offsetHeight)})
 
 
111
  }
112
 
113
  Counter(focus, size){
 
158
  sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"
159
  ></iframe>
160
  </div>
161
+ { this.state.size && !navigator.userAgent.match(/firefox|fxios/i) && <>
162
 
163
  <div id="remove-ghost" className={`absolute select-none -bottom-0 right-0 w-5 h-5border-2 shadow-2xl rounded-xl z-10 cursor-nwse-resize hover:opacity-50 `}
164
  style={{"userDrag": "none"}}
frontend/src/css/dist/output.css CHANGED
@@ -888,6 +888,18 @@ video {
888
  height: 2rem;
889
  }
890
 
 
 
 
 
 
 
 
 
 
 
 
 
891
  .w-full {
892
  width: 100%;
893
  }
@@ -940,6 +952,10 @@ video {
940
  width: 100vw;
941
  }
942
 
 
 
 
 
943
  .max-w-full {
944
  max-width: 100%;
945
  }
 
888
  height: 2rem;
889
  }
890
 
891
+ .h-\[500px\] {
892
+ height: 500px;
893
+ }
894
+
895
+ .h-\[300px\] {
896
+ height: 300px;
897
+ }
898
+
899
+ .h-\[350px\] {
900
+ height: 350px;
901
+ }
902
+
903
  .w-full {
904
  width: 100%;
905
  }
 
952
  width: 100vw;
953
  }
954
 
955
+ .w-\[80\%\] {
956
+ width: 80%;
957
+ }
958
+
959
  .max-w-full {
960
  max-width: 100%;
961
  }
frontend/src/css/index.css CHANGED
@@ -11,3 +11,16 @@ code {
11
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
  monospace;
13
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
  monospace;
13
  }
14
+
15
+
16
+ /* Chrome, Safari, Edge, Opera */
17
+ input::-webkit-outer-spin-button,
18
+ input::-webkit-inner-spin-button {
19
+ -webkit-appearance: none;
20
+ margin: 0;
21
+ }
22
+
23
+ /* Firefox */
24
+ input[type=number] {
25
+ -moz-appearance: textfield;
26
+ }