import React, { Component } from 'react'; import { BrowserRouter as Router, Route } from 'react-router-dom' import Loading from './pages/loading.js'; import Login from './pages/login.js'; import SelectCommand from './pages/select_command.js'; import Command from './pages/command.js'; import History from './pages/history.js'; import Job from './pages/job.js'; import Header from './blocks/header.js'; import { api, httpGET } from './http.js'; import './app.css'; export default class App extends Component { constructor(props) { super(props); this.state = { authorized: null, user: null, commands: null, commands_query: "" }; this.loadAuth(); this.loadCommands(); } loadAuth() { httpGET(api("/auth/session"), (status, body) => { if (status === 200) { this.setState({ authorized: true, user: JSON.parse(body) }); } else { this.setState({authorized: false}); } }, (error) => { console.log("Failed to load auth details:", error); this.setState({authorized: false}); } ); } loadCommands() { httpGET(api("/commands"), (status, body) => { if (status === 200) { let list = JSON.parse(body); var hash = {}; for (var cmd of list) { hash[cmd.name] = cmd; } this.setState({commands: hash}); } }, (error) => { this.setState({commands: {}}); console.log("Failed to load commands:", error); } ); } render() { if (this.state.authorized === null || this.state.commands === null) { return ; } if (this.state.authorized === false) { return ; } return (
( )}/> {/* Command */} ( )}/> {/* Logs */} ( )}/> {/* History */} ( )}/> ( )}/> ( )}/>
); } queryHandler(event) { this.setState({ commands_query: event.target.value, }); } }