{"size": 1485, "ext": "js", "max_stars_repo_path": "src/components/AllUserInfo.js", "max_stars_repo_name": "Zhiyu-Michael-Wang/TeacherInformationManagementService", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/AllUserInfo.js", "max_issues_repo_name": "Zhiyu-Michael-Wang/TeacherInformationManagementService", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/AllUserInfo.js", "max_forks_repo_name": "Zhiyu-Michael-Wang/TeacherInformationManagementService", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.203125, "max_line_length": 89, "alphanum_fraction": 0.4491582492}
import React from 'react'
import { Card } from 'semantic-ui-react'
import CreateUser from './CreateUser'
import UserList from './UserList'
import axios from 'axios'



class AllUserInfo extends React.Component {

    constructor() {
        super()
        this.state = {
            users: [],
            userOnCreation: {}
        }
        this.onSubmitData = this.onSubmitData.bind(this)
    }

    getData(){
        const self = this
        axios.get('http://localhost:5001/users/')
            .then(response => {
                if (response.data.length > 0){
                    self.setState({
                        users: response.data
                    })
                    
                    console.log('user list refreshed')
                }
            })
    }

    componentDidMount() {
        this.getData()
    }

    onSubmitData(user){
        axios.post('http://localhost:5001/users/add', user)
            .then(res => {
                this.getData()
            })
        
    }

    

    render() {


        return (
            <div className="AllUserInfo" style={{ maxWidth: "1000px", margin: "auto" }}>
                
                <Card.Group centered>
                    <UserList users={this.state.users}/>
                    <CreateUser onSubmitData={this.onSubmitData}/>
                </Card.Group>
            </div>
        )
    }
}


export default AllUserInfo