1
1
import logo from './logo.svg' ;
2
2
import './App.css' ;
3
+ import axios from 'axios'
3
4
import Button from '@mui/material/Button' ;
4
5
import Grid from '@mui/material/Grid'
5
6
import React , { useState , useEffect } from 'react' ;
@@ -9,8 +10,33 @@ import Box from '@mui/material/Box';
9
10
import Stack from '@mui/material/Stack' ;
10
11
11
12
function App ( ) {
12
-
13
13
const [ currentTime , setCurrentTime ] = useState ( new Date ( ) ) ;
14
+ const [ clusterData , setClusterData ] = useState ( null ) ;
15
+
16
+ const getClusters = async ( ) => {
17
+ return axios . get ( 'http://127.0.0.1:5000/[email protected] ' )
18
+ . then ( function ( res ) {
19
+ if ( res . data . clusters !== null ) {
20
+ console . log ( res )
21
+ return ( res . data . clusters )
22
+ }
23
+ } )
24
+ . catch ( function ( res ) {
25
+ if ( res . response ) {
26
+ console . log ( res . response . data . reason + " Please wait a few seconds and try reloading the page." ) ;
27
+ } else {
28
+ console . log ( "Something went wrong. Please wait a few seconds and try reloading the page." )
29
+ }
30
+ } ) ;
31
+ }
32
+
33
+ useEffect ( ( ) => {
34
+ if ( clusterData === null ) {
35
+ getClusters ( ) . then ( ( res ) => {
36
+ setClusterData ( res )
37
+ } )
38
+ }
39
+ } , [ clusterData ] )
14
40
15
41
useEffect ( ( ) => {
16
42
const interval = setInterval ( ( ) => {
@@ -19,28 +45,55 @@ function App() {
19
45
return ( ) => clearInterval ( interval ) ;
20
46
} , [ ] ) ;
21
47
22
- return (
48
+ function getClustersComponent ( ) {
49
+ const clusters = [ ]
50
+ for ( var i = 0 ; i < clusterData . length ; i ++ ) {
51
+ const cluster = clusterData [ i ] ;
52
+ const preview = < Cluster title = { cluster . name } > </ Cluster >
53
+ clusters . push ( preview )
54
+ }
55
+ return clusters
56
+ }
57
+
58
+ if ( clusterData ) {
59
+ return (
60
+
61
+ < div className = "App" >
62
+ < Box
63
+ sx = { { margin : 2 } } >
64
+ < Box sx = { { margin : 20 } } > </ Box >
65
+ < div className = 'Time' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > { currentTime . toLocaleTimeString ( ) } </ div >
66
+ < div className = 'HelloMessage' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > Good morning, Ayushi.</ div >
67
+ < Box
68
+ sx = { { m : 10 } } > </ Box >
69
+ < div className = "Workspaces" >
70
+ < Stack direction = "row" spacing = { 4 } justifyContent = "center" >
71
+ { getClustersComponent ( ) }
72
+ </ Stack >
73
+ </ div >
74
+ </ Box >
75
+ </ div >
23
76
24
- < div className = "App" >
25
- < Box
26
- sx = { { margin : 2 } } >
27
- < Box sx = { { margin : 20 } } > </ Box >
28
- < div className = 'Time' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > { currentTime . toLocaleTimeString ( ) } </ div >
29
- < div className = 'HelloMessage' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > Good morning, Ayushi. </ div >
30
- < Box
31
- sx = { { m : 10 } } > </ Box >
32
- < div className = "Workspaces" >
33
- < Stack direction = "row" spacing = { 4 } justifyContent = "center" >
34
- < Cluster title = "CS 189" > </ Cluster >
35
- < Cluster title = "CS 170" > </ Cluster >
36
- < Cluster title = "UGBA 105" > </ Cluster >
37
- < Cluster title = "R1B" > </ Cluster >
38
- </ Stack >
39
- </ div >
40
- </ Box >
41
- </ div >
42
-
43
- ) ;
77
+ ) ;
78
+ } else {
79
+ return (
80
+ < div className = "App" >
81
+ < Box
82
+ sx = { { margin : 2 } } >
83
+ < Box sx = { { margin : 20 } } > </ Box >
84
+ < div className = 'Time' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > { currentTime . toLocaleTimeString ( ) } </ div >
85
+ < div className = 'HelloMessage' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > Good morning, Ayushi. </ div >
86
+ < Box
87
+ sx = { { m : 10 } } > </ Box >
88
+ < div className = "Workspaces" >
89
+ < Stack direction = "row" spacing = { 4 } justifyContent = "center" >
90
+ < div className = 'HelloMessage' style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } > Loading workspaces. </ div >
91
+ </ Stack >
92
+ </ div >
93
+ </ Box >
94
+ </ div >
95
+ ) ;
96
+ }
44
97
}
45
98
46
99
export default App ;
0 commit comments