LucaVivona commited on
Commit
fdbdfe8
·
1 Parent(s): a335474

refactor navagation bar 🧭

Browse files
frontend/src/components/Navagation/navbar.js CHANGED
@@ -12,9 +12,9 @@ export default class Navbar extends Component{
12
  constructor(props){
13
  super(props)
14
  this.temp_host = 0
15
- this.fetch_classes()
16
  this.deleteNode = props.onDelete
17
- this.state = {open : true,
 
18
  menu : [],
19
  colour : props.colour || [],
20
  text : "",
@@ -27,28 +27,26 @@ export default class Navbar extends Component{
27
 
28
  }
29
 
 
 
 
 
30
 
31
  /**
32
  * Asynchronously call the Flask api server every second to check if there exist a gradio application info
33
  * @return null
34
  */
35
- async fetch_classes(){
36
  try {
37
  setInterval( async () => {
38
- const menu = []
39
  await fetch("http://localhost:2000/api/open/ports", { method: 'GET', mode : 'cors',})
40
  .then(response => response.json())
41
  .then(data => {
42
- for (var i = 0; i < data.length; i++){
43
- menu.push(data[i])
44
- }
45
  })
46
  .catch(error => {console.log(error)})
47
-
48
- var diff = menu.length - this.state.menu.length
49
- if(diff !== 0){
50
- this.handelTabs(menu, diff)
51
- }
52
  },1000);
53
  }catch(e){
54
  console.log(e)
@@ -137,25 +135,26 @@ export default class Navbar extends Component{
137
  // remove
138
  var c = []
139
  var j = []
140
- if(d < 0){
 
141
  var a = this.state.menu.filter(item => !e.includes(item)) // get the items not in menu anymore
142
  c = this.state.colour
143
  j = this.state.emoji
144
- for(var k=0; k < d; k++){
145
  c.splice(this.state.menu.indexOf(a[k]), 1)
146
  j.splice(this.state.menu.indexOf(a[k]), 1)
147
  }
148
- this.setState({'menu' : e, 'colour' : c, 'emoji' : j})
149
  }else{
150
  //append new colours
151
- for(var i =0; i < d; i++){
152
  c.push(random_colour(i === 0 ? null : c[i-1]));
153
  j.push(random_emoji(i === 0 ? null : c[i-1]));
154
 
155
  }
156
  const colour = [...this.state.colour]
157
  const emoji = [...this.state.emoji]
158
- this.setState({'menu' : e, 'colour' : [...colour, ...c], 'emoji' : [...emoji, ...j],})
159
  }
160
  }
161
 
 
12
  constructor(props){
13
  super(props)
14
  this.temp_host = 0
 
15
  this.deleteNode = props.onDelete
16
+ this.state = {
17
+ open : true,
18
  menu : [],
19
  colour : props.colour || [],
20
  text : "",
 
27
 
28
  }
29
 
30
+ componentDidMount(){
31
+ this.fetch_classes()
32
+
33
+ }
34
 
35
  /**
36
  * Asynchronously call the Flask api server every second to check if there exist a gradio application info
37
  * @return null
38
  */
39
+ fetch_classes = async () => {
40
  try {
41
  setInterval( async () => {
 
42
  await fetch("http://localhost:2000/api/open/ports", { method: 'GET', mode : 'cors',})
43
  .then(response => response.json())
44
  .then(data => {
45
+ this.handelTabs(this.state.menu,data, data)
46
+ this.setState({menu : data})
 
47
  })
48
  .catch(error => {console.log(error)})
49
+
 
 
 
 
50
  },1000);
51
  }catch(e){
52
  console.log(e)
 
135
  // remove
136
  var c = []
137
  var j = []
138
+ if (d.length - e.length === 0) return
139
+ else if(d.length - e.length <= 0){
140
  var a = this.state.menu.filter(item => !e.includes(item)) // get the items not in menu anymore
141
  c = this.state.colour
142
  j = this.state.emoji
143
+ for(var k=0; k < d.length; k++){
144
  c.splice(this.state.menu.indexOf(a[k]), 1)
145
  j.splice(this.state.menu.indexOf(a[k]), 1)
146
  }
147
+ this.setState({'colour' : c, 'emoji' : j})
148
  }else{
149
  //append new colours
150
+ for(var i =0; i < d.length; i++){
151
  c.push(random_colour(i === 0 ? null : c[i-1]));
152
  j.push(random_emoji(i === 0 ? null : c[i-1]));
153
 
154
  }
155
  const colour = [...this.state.colour]
156
  const emoji = [...this.state.emoji]
157
+ this.setState({'colour' : [...colour, ...c], 'emoji' : [...emoji, ...j],})
158
  }
159
  }
160
 
frontend/src/components/ReactFlow/ReactFlowEnv.js CHANGED
@@ -42,6 +42,7 @@ export default function ReactEnviorment() {
42
  if(flow){
43
  flow.nodes.map((nds) => nds.data.delete = deleteNode)
44
  setNodes(flow.nodes || [])
 
45
  console.log(flow)
46
  }
47
  }
 
42
  if(flow){
43
  flow.nodes.map((nds) => nds.data.delete = deleteNode)
44
  setNodes(flow.nodes || [])
45
+ setEdges(flow.edges || [])
46
  console.log(flow)
47
  }
48
  }