LucaVivona commited on
Commit
ed0ac7b
·
1 Parent(s): e629239

refector navbar 🚧

Browse files
frontend/src/components/Modal/importer.js CHANGED
@@ -18,12 +18,12 @@ export default function Import(props){
18
  size='larg'
19
  >
20
  <div className='w-full shadow-lg rounded-lg'>
21
- <ul class="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 class="mr-2" 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 class="mr-2">
26
- <button id="services-tab" data-tabs-target="#Streamlit" type="button" role="tab" aria-controls="services" aria-selected="false" className="inline-block p-4 opacity-30"><Streamlit className=" w-20 h-10"/></button>
27
  </li>
28
  </ul>
29
  <div className='absolute right-5 top-5 z-20 mr-5'
@@ -36,11 +36,11 @@ export default function Import(props){
36
  </div>
37
  { tab === "gradio" &&
38
  <div className='w-full bg-white'>
39
- <ul class="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 class="" 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 class="" 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>
@@ -76,7 +76,7 @@ export default function Import(props){
76
  function Local(props){
77
  return (
78
  <div className='p-5'>
79
- <Message floating color=''>
80
 
81
  <Message.Header>🏗️ Comming soon...</Message.Header>
82
  <Message.Content className='p-5'>
@@ -112,7 +112,7 @@ function Shared(props){
112
  if (e.key.includes("Enter")) props.appendHandler()
113
  }}>
114
  <div className='p-5'>
115
- <Message color='' floating>
116
  <div className={`flex items-center rounded-md bg-light-white mt-6 border-dashed`}>
117
  <label className="relative block w-full p-5 focus:shadow-xl">
118
  <span className={`absolute inset-y-0 left-0 flex items-center pl-8`}>
 
18
  size='larg'
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'
 
36
  </div>
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>
 
76
  function Local(props){
77
  return (
78
  <div className='p-5'>
79
+ <Message floating>
80
 
81
  <Message.Header>🏗️ Comming soon...</Message.Header>
82
  <Message.Content className='p-5'>
 
112
  if (e.key.includes("Enter")) props.appendHandler()
113
  }}>
114
  <div className='p-5'>
115
+ <Message floating>
116
  <div className={`flex items-center rounded-md bg-light-white mt-6 border-dashed`}>
117
  <label className="relative block w-full p-5 focus:shadow-xl">
118
  <span className={`absolute inset-y-0 left-0 flex items-center pl-8`}>
frontend/src/components/Navagation/navbar.js CHANGED
@@ -44,7 +44,7 @@ export default class Navbar extends Component{
44
 
45
  var diff = menu.length - this.state.menu.length
46
  if(diff !== 0){
47
- this.hanelTabs(menu, diff)
48
  }
49
  },1000);
50
  }catch(e){
@@ -68,48 +68,19 @@ export default class Navbar extends Component{
68
  !pattern.share.test(this.state.text) &&
69
  !pattern.hugginFace.test(this.state.text))){
70
 
71
- this.setState({open : this.state.open,
72
- menu : this.state.menu,
73
- text: '',
74
- name : '',
75
- colour : this.state.colour,
76
- emoji : this.state.emoji,
77
- error : true,
78
- modal : this.state.modal })
79
  return
80
  }
81
 
82
  fetch(this.state.text, {method : "GET", mode: 'no-cors'}).then((re) => {
83
- //console.log(re)
84
  fetch("http://localhost:2000/api/append/port", {method: 'POST', mode : 'cors', headers : { 'Content-Type' : 'application/json' }, body: JSON.stringify({file : "", kwargs : {}, name : this.state.name === "" ?`temp_class_${this.temp_host++}` : `${this.state.name}`, port: 0 , host : this.state.text}) }).then(resp => {
85
- this.setState({open : this.state.open,
86
- menu : this.state.menu,
87
- text: "",
88
- name : "",
89
- colour : this.state.colour,
90
- emoji : this.state.emoji,
91
- error : false,
92
- modal : false })
93
 
94
- }).catch(() => this.setState({open : this.state.open,
95
- menu : this.state.menu,
96
- text: '',
97
- name : '',
98
- colour : this.state.colour,
99
- emoji : this.state.emoji,
100
- error : true,
101
- modal : this.state.modal }))
102
- }).catch((err)=>{
103
- //console.log(err)
104
- this.setState({open : this.state.open,
105
- menu : this.state.menu,
106
- text: '',
107
- name : '',
108
- colour : this.state.colour,
109
- emoji : this.state.emoji,
110
- error : true,
111
- modal : this.state.modal })
112
- })
113
  }
114
 
115
  /**
@@ -117,14 +88,8 @@ export default class Navbar extends Component{
117
  * @param {*} bool boolean of the current state of the modal
118
  */
119
  handelModal = (bool) => {
120
- this.setState({open : this.state.open,
121
- menu : this.state.menu,
122
- text: this.state.text,
123
- name: this.state.name,
124
- colour : this.state.colour,
125
- emoji : this.state.emoji,
126
- error : !bool ? false : this.state.error ,
127
- modal : bool})
128
  }
129
 
130
  /**
@@ -161,7 +126,7 @@ export default class Navbar extends Component{
161
  * @param {*} e current menu
162
  * @param {*} d integer variable of the diffence between the current menu and new menu updated ment
163
  */
164
- hanelTabs = (e, d) => {
165
  // if less then 0 we must remove colour's and emoji's
166
  // get index of the object
167
  // remove
@@ -175,7 +140,7 @@ export default class Navbar extends Component{
175
  c.splice(this.state.menu.indexOf(a[k]), 1)
176
  j.splice(this.state.menu.indexOf(a[k]), 1)
177
  }
178
- this.setState({open : this.state.open, menu : e, text: this.state.text, name: this.state.name, colour : c, emoji : j, error : this.state.error, modal : this.state.modal })
179
  }else{
180
  //append new colours
181
  for(var i =0; i < d; i++){
@@ -183,7 +148,9 @@ export default class Navbar extends Component{
183
  j.push(random_emoji(i === 0 ? null : c[i-1]));
184
 
185
  }
186
- this.setState({open : this.state.open, menu : e, text: this.state.text, name: this.state.name, colour : [...this.state.colour, ...c], emoji : [...this.state.emoji, ...j], error : this.state.error, modal : this.state.modal })
 
 
187
  }
188
  }
189
 
@@ -191,7 +158,7 @@ export default class Navbar extends Component{
191
  * handel navagation open and close function
192
  */
193
  handelNavbar = () => {
194
- this.setState({open : !this.state.open, menu : this.state.menu, text: this.state.text, name: this.state.name, colour : this.state.colour, emoji : this.state.emoji, error : this.state.error, modal : this.state.modal })
195
  }
196
 
197
  /**
@@ -200,8 +167,7 @@ export default class Navbar extends Component{
200
  * @param {*} type : text | name string that set the changed value of the input to the current value
201
  */
202
  updateText = (e, type) => {
203
- console.log(this.state.open)
204
- this.setState({open : this.state.open, menu : this.state.menu, text: type === "text" ? e.target.value : this.state.text, name: type === "name" ? e.target.value : this.state.name, colour : this.state.colour, emoji : this.state.emoji, error : this.state.error, modal : this.state.modal })
205
  }
206
 
207
  /**
@@ -248,81 +214,7 @@ export default class Navbar extends Component{
248
  textHandler={this.updateText}
249
  appendHandler={this.append_gradio}
250
  catch={this.state.error}/>
251
- {/* <Modal
252
- basic
253
- open={this.state.modal}
254
- size='small'
255
- >
256
- <Header className="select-none space-y-4" icon>
257
- 🌐
258
- <br/>
259
- Append Shared Gradio Hosts
260
- </Header>
261
- <Modal.Content>
262
- <div className=" text-center select-none">Host other HugginFace Models or Gradio application via shared link</div>
263
- <div className={`flex items-center rounded-md bg-light-white mt-6 border-dashed`}>
264
- <label className="relative block w-full">
265
- <span className={`absolute inset-y-0 left-0 flex items-center pl-3`}>
266
- <BsSearch className="block float-left cursor-pointer mr-2"/>
267
- </span>
268
- <input className={`placeholder:italic placeholder:text-slate-400 block bg-transparent w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 ${this.state.open ? "pr-3" : "hidden"} shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm bg-transparent`}
269
- placeholder={`stream link...`}
270
- type="text" name="search"
271
- onChange={(e) => {
272
- this.updateText(e, "text")
273
- }}
274
-
275
- />
276
- </label>
277
- </div>
278
- <div className={`flex items-center rounded-md bg-light-white mt-6 border-dashed`}>
279
- <label className="relative block w-full">
280
- <span className={`absolute inset-y-0 left-0 flex items-center pl-3`}>
281
- <Icon className="block float-left cursor-pointer mr-2" name="address card"/>
282
- </span>
283
- <input className={`placeholder:italic placeholder:text-slate-400 block bg-transparent w-full border border-slate-300 border-dashed rounded-md py-2 pl-9 ${this.state.open ? "pr-3" : "hidden"} shadow-sm focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm`}
284
- placeholder={`Give it name...` }
285
- type="text" name="search"
286
- onChange={(e) => {
287
- this.updateText(e, "name")
288
- }}
289
- autoComplete='off'
290
- />
291
- </label>
292
- </div>
293
-
294
- { this.state.error &&
295
- <Message negative>
296
- <Message.Header className=" text-lg text-center">🚫 Something went wrong...</Message.Header>
297
- <br/>
298
- <h1 className=" underline pb-3 font-bold text-lg">🤔 Possible Things That could of happen <br/></h1>
299
- <ul className="font-bold">
300
- <li key={"error_1"}>- The input was empty</li>
301
- <li key={"error_2"}>- The connection was forbidden</li>
302
- <li key={"error_3"}>- The name was already taken</li>
303
- <li key={"error_4"}>- The link you gave did not pass the regex</li>
304
- <ul className="px-6">
305
- <li key={"error_5"}>- http://localhost:xxxx</li>
306
- <li key={"error_6"}>- http://xxxxx.gradio.app</li>
307
- <li key={"error_7"}>- https://hf.space/embed/$user/$space_name/+</li>
308
- </ul>
309
- <li>- link already exist within the menu</li>
310
- </ul>
311
-
312
- </Message>
313
- }
314
-
315
- </Modal.Content>
316
- <Modal.Actions>
317
- <Button basic color='red' inverted onClick={() => {this.handelModal(false)}}>
318
- <Icon name='remove' /> Exit
319
- </Button>
320
- <Button color='green' inverted onClick={() => {this.append_gradio()}}>
321
- <Icon name='checkmark' /> Append
322
- </Button>
323
- </Modal.Actions>
324
- </Modal> */}
325
-
326
  <div className=" relative z-10 h-auto overflow-auto pt-4">
327
  <ul className="pt-2">
328
  {this.state.menu.map((menu, index) => {return this.subComponents(menu, index)})}
 
44
 
45
  var diff = menu.length - this.state.menu.length
46
  if(diff !== 0){
47
+ this.handelTabs(menu, diff)
48
  }
49
  },1000);
50
  }catch(e){
 
68
  !pattern.share.test(this.state.text) &&
69
  !pattern.hugginFace.test(this.state.text))){
70
 
71
+ this.setState({
72
+ 'text': '',
73
+ 'name': '',
74
+ 'error': true})
 
 
 
 
75
  return
76
  }
77
 
78
  fetch(this.state.text, {method : "GET", mode: 'no-cors'}).then((re) => {
 
79
  fetch("http://localhost:2000/api/append/port", {method: 'POST', mode : 'cors', headers : { 'Content-Type' : 'application/json' }, body: JSON.stringify({file : "", kwargs : {}, name : this.state.name === "" ?`temp_class_${this.temp_host++}` : `${this.state.name}`, port: 0 , host : this.state.text}) }).then(resp => {
80
+ this.setState({'text': "",'name' : "",'error' : false,'modal' : false })
 
 
 
 
 
 
 
81
 
82
+ }).catch(() => this.setState({'text': '', 'name' : '', 'error' : true, }))
83
+ }).catch((err)=> this.setState({'text': '','name' : '', 'error' : true,}))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
  /**
 
88
  * @param {*} bool boolean of the current state of the modal
89
  */
90
  handelModal = (bool) => {
91
+ this.setState({'error' : !bool ? false : this.state.error ,
92
+ 'modal' : bool})
 
 
 
 
 
 
93
  }
94
 
95
  /**
 
126
  * @param {*} e current menu
127
  * @param {*} d integer variable of the diffence between the current menu and new menu updated ment
128
  */
129
+ handelTabs = async (e, d) => {
130
  // if less then 0 we must remove colour's and emoji's
131
  // get index of the object
132
  // remove
 
140
  c.splice(this.state.menu.indexOf(a[k]), 1)
141
  j.splice(this.state.menu.indexOf(a[k]), 1)
142
  }
143
+ this.setState({'menu' : e, 'colour' : c, 'emoji' : j})
144
  }else{
145
  //append new colours
146
  for(var i =0; i < d; i++){
 
148
  j.push(random_emoji(i === 0 ? null : c[i-1]));
149
 
150
  }
151
+ const colour = [...this.state.colour]
152
+ const emoji = [...this.state.emoji]
153
+ this.setState({'menu' : e, 'colour' : [...colour, ...c], 'emoji' : [...emoji, ...j],})
154
  }
155
  }
156
 
 
158
  * handel navagation open and close function
159
  */
160
  handelNavbar = () => {
161
+ this.setState({'open' : !this.state.open})
162
  }
163
 
164
  /**
 
167
  * @param {*} type : text | name string that set the changed value of the input to the current value
168
  */
169
  updateText = (e, type) => {
170
+ this.setState({[`${type}`] : e.target.value })
 
171
  }
172
 
173
  /**
 
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">
219
  <ul className="pt-2">
220
  {this.state.menu.map((menu, index) => {return this.subComponents(menu, index)})}