App.js 3.37 KB
import React, {Component, components} from 'react';
import Student from './components/Student';
import './App.css';
import Paper from '@material-ui/core/Paper'
import Table from '@material-ui/core/Table'
import TableHead from '@material-ui/core/TableHead'
import TableBody from '@material-ui/core/TableBody'
import TableRow from '@material-ui/core/TableRow'
import TableCell from '@material-ui/core/TableCell'
import {withStyles} from '@material-ui/core/styles';
import curcularProgress from '@material-ui/core/CircularProgress';
import CircularProgress from '@material-ui/core/CircularProgress';

const styles = theme => ({
  root: {
    width: '100%',
    marginTop: theme.spacing.unit * 3,
    overflowX: "auto"
  },
  table: {
    minWidth:1000
  },
  progress:{
    margin: theme.spacing.unit * 2
  }
})

const students = [
  {
  'st_Code': 6666,
  'st_Name': '육현진',
  'st_Id': 2018102210,
  'st_Major':'컴퓨터공학과',
  'st_Midscore': 100,
  'st_Finalscore': 100,
  'st_Assignscore': 100,
  'st_Attendscore': 100,
  'st_Score':'A+'
},
{
  'st_Code': 1111,
  'st_Name': '김창동',
  'st_Id': 2020021120,
  'st_Major':'컴퓨터공학과',
  'st_Midscore': 79,
  'st_Finalscore': 85,
  'st_Assignscore': 100,
  'st_Attendscore': 90,
  'st_Score':'A0'
}]

class App extends Component{

  state = {
    students: "",
    completed: 0
  }

  componentDidMount() {
    this.timer= setInterval(this.progress,20);
    this.callApi()
      .then(res => this.setState({students: res}))
      .catch(err => console.log(err));
  }

  callApi=async()=>{
    const response = await fetch('/api/students');
    const body = await response.json();
    return body;
  }

  progress=() =>{
    const{completed}= this.state;
    this.setState({completed:completed >= 100 ?0:completed +1});
  }

  render(){

    const {classes}= this.props;

      return (  
        <Paper className={classes.root}>
          <Table className={classes.table}>

          <TableHead>
            <TableRow>
            <TableCell>코드번호</TableCell>
            <TableCell>이름</TableCell>
            <TableCell>학번</TableCell>
            <TableCell>전공</TableCell>
            <TableCell>중간</TableCell>
            <TableCell>기말</TableCell>
            <TableCell>과제</TableCell>
            <TableCell>출석</TableCell>
            <TableCell>학점</TableCell>
            </TableRow>
          </TableHead>
            
            <TableBody>
            {
            this.state.students ?
            this.state.students.map(c=>{
              return (
                <Student
                  key={c.st_Code}
                  st_Code={c.st_Code}
                  st_Name={c.st_Name}
                  st_Id={c.st_Id}
                  st_Major={c.st_Major}
                  st_Midscore={c.st_Midscore}
                  st_Finalscore={c.st_Finalscore}
                  st_Assignscore={c.st_Assignscore}
                  st_Attendscore={c.st_Attendscore}
                  st_Score={c.st_Score}
                  />
              );
            }) : 
            <TableRow>
              <TableCell colSpan="9" allign="center">
                <CircularProgress className={classes.progress} variant="determinate" value={this.state.completed}/>
              </TableCell>
            </TableRow>
          } 
            </TableBody>

          </Table>

        </Paper>

  );
  }
}

export default withStyles(styles)(App);