feat: prefix and anti multi-check

This commit is contained in:
KirinBaka
2025-04-22 15:34:22 +08:00
parent bebf2c9640
commit ffc89fd069
10 changed files with 46 additions and 28 deletions

View File

@@ -79,10 +79,13 @@ const Timetable = ({
if (disableNetwork) return;
// Immediately revert the checkbox state
target.checked = !target.checked;
// post request
const json = await post("/api/record", {
name: target.name,
checked: target.checked,
checked: !target.checked,
user,
});
if (json.error !== undefined) {
@@ -100,6 +103,7 @@ const Timetable = ({
const handleInput = (event: React.ChangeEvent<HTMLInputElement>): boolean => {
const { target } = event;
// validate
if (target?.children[0]?.tagName !== "TABLE") {
console.log("not a table");
@@ -202,7 +206,7 @@ const Timetable = ({
}
const occupied: string[] = json.occupied;
const myselect: string[] = json.myselect;
console.log(json);
// console.log(json);
for (const index in indexToElement) {
if (occupied.includes(index)) {
indexToElement[index].style.display = "none";
@@ -226,7 +230,7 @@ const Timetable = ({
const interval = setInterval(() => {
refresh();
}, 1000);
}, 1500);
return () => {
clearInterval(interval);
};
@@ -264,7 +268,9 @@ const Timetable = ({
return (
<>
<h2 style={{ textAlign: "center" }}>Login as {user}</h2>
<h2 style={{ textAlign: "center" }}>ITSC </h2>
<h3 style={{ textAlign: "center" }}>Login as {user}</h3>
<h3 style={{ textAlign: "center" }}></h3>
<div
align="center"
ref={ref}
@@ -273,7 +279,7 @@ const Timetable = ({
overflow: "scroll",
}}
onInput={handleInput}
></div>{" "}
></div>
{!hideDownloadButton && (
<p style={{ display: "flex", justifyContent: "center" }}>
<button onClick={DownloadMarks}>Download Selection</button>

View File

@@ -6,7 +6,7 @@ const UserInputWrap = ({ children, setUser }) => {
const [begin, setBegin] = React.useState(false);
React.useEffect(() => {
setInputUser(localStorage.getItem("user") || "");
setInputUser(localStorage.getItem("username") || "");
}, []);
return (
@@ -17,9 +17,10 @@ const UserInputWrap = ({ children, setUser }) => {
display: "grid",
placeItems: "center",
alignItems: "center",
minHeight: "100vh",
// minHeight: "100vh",
}}
>
<h2 style={{ textAlign: "center" }}>ITSC </h2>
<div>
<input
style={{
@@ -45,7 +46,7 @@ const UserInputWrap = ({ children, setUser }) => {
}
setUser(inputUser.trim());
setBegin(true);
localStorage.setItem("user", inputUser.trim());
localStorage.setItem("username", inputUser.trim());
}}
>
Login