Debug.js
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import axios from "axios";
import { useState } from "react";
import { useNavigate } from "react-router-dom";
//import { login } from "../libs/E_Campus";
import "../styles/Debug.css";
import { initTempSubjects } from "../utils/Test";
const Debug = () => {
console.log("visit Debug");
const [state, setState] = useState({
type: "login",
input1: "",
input2: "",
output: "",
});
const handleChangeState = (e) => {
setState({
...state,
[e.target.name]: e.target.value,
});
};
const handleSubmit = async (e) => {
let result;
switch (state.type) {
case "initSubjects":
await initTempSubjects();
result = "inited";
break;
case "login":
//result = login(state.input1, state.input2);
break;
case "server":
setState({ ...state, output: "loading..." });
axios
.post("http://localhost:3001/login/", {
id: state.input1,
pw: state.input2,
})
.then((res) => {
setState({ ...state, output: res.data });
});
return;
default:
}
setState({ ...state, output: result });
};
const navigate = useNavigate();
return (
<div className="Debug">
<div>
<button
onClick={() => {
navigate("/home");
}}
>
Home
</button>
</div>
<div className="dd">
<div>
<span>type : </span>
<select name="type" value={state.type} onChange={handleChangeState}>
<option value={"initSubjects"}>initSubjects</option>
<option value={"login"}>login</option>
<option value={"server"}>server</option>
</select>
</div>
<input
value={state.input1}
onChange={handleChangeState}
name="input1"
/>
<input
value={state.input2}
onChange={handleChangeState}
name="input2"
/>
<button onClick={handleSubmit}>Enter</button>
<div>{"result : \n" + state.output}</div>
</div>
</div>
);
};
export default Debug;