add report page

This commit is contained in:
2023-02-03 22:47:51 +08:00
parent 5e016dccef
commit e77173a8af
3 changed files with 55 additions and 2 deletions

View File

@@ -62,7 +62,7 @@ const Timetable = ({ user }) => {
// revert conflict changed input
for (const { input, disable } of changedInputs) {
if (disable) {
input.addAttribute("disabled", "true");
input.setAttribute("disabled", "true");
} else {
input.removeAttribute("disabled");
}
@@ -154,7 +154,7 @@ const Timetable = ({ user }) => {
// after checked, find conflicts input
if (includes) {
for (const input of conflicts[index]) {
console.log("conflict", input);
if (input.name === index) continue;
input.setAttribute("disabled", "true");
}
}

50
pages/report.tsx Normal file
View File

@@ -0,0 +1,50 @@
import React from "react";
import Head from "next/head";
const ReportPage = () => {
const ref = React.useRef();
const getReport = async () => {
const resp = await fetch("/api/html").then((resp) => resp.json());
ref.current.innerHTML = resp.html;
const json: Record<string, string> = await fetch("/api/admin").then(
(resp) => resp.json()
);
const table = ref.current.children[0];
const tbody = table.children[table.children.length - 1];
for (const tr_index in tbody.children) {
const tr = tbody.children[tr_index];
for (const td_index in tr.children) {
const td = tr.children[td_index];
if (td.tagName !== "TD") continue;
const index = `${tr_index},${td_index}`;
if (json[index] === undefined) continue;
td.innerHTML = json[index];
}
}
};
React.useEffect(() => {
getReport();
}, []);
return (
<>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<button onClick={async () => getReport()}>Refresh</button>
<div
ref={ref}
onInput={(event) => {
console.log(event.currentTarget.innerHTML);
}}
contentEditable="true"
></div>
</main>
</>
);
};
export default ReportPage;

View File

@@ -11,3 +11,6 @@ const result = await fetch("http://localhost:3000/api/admin", {
}).then(resp => resp.text())
console.log(result)
// set begin
await fetch('http://localhost:3000/api/begin')