common get post method, and control, edit page
This commit is contained in:
56
pages/control.tsx
Normal file
56
pages/control.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from "react";
|
||||
import Head from "next/head";
|
||||
import { get, post } from "@/common";
|
||||
|
||||
const ControlPage = () => {
|
||||
const [isBegin, setIsBegin] = React.useState(false);
|
||||
const [inputLimit, setInputLimit] = React.useState("2");
|
||||
const toggleBegin = async () => {
|
||||
const json = await post("/api/config", { begin: !isBegin });
|
||||
setIsBegin(json.begin);
|
||||
};
|
||||
const refresh = async () => {
|
||||
const json = await get("/api/config");
|
||||
setInputLimit(json.limit);
|
||||
setIsBegin(json.begin);
|
||||
};
|
||||
React.useEffect(() => {
|
||||
refresh();
|
||||
}, []);
|
||||
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>
|
||||
<p>
|
||||
<button onClick={() => toggleBegin()}>
|
||||
{isBegin ? "Begin" : "Pause"}
|
||||
</button>
|
||||
</p>
|
||||
<p>
|
||||
<input
|
||||
value={inputLimit}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setInputLimit(event.target.value)
|
||||
}
|
||||
/>
|
||||
<button
|
||||
onClick={() => {
|
||||
post("/api/config", {
|
||||
limit: parseInt(inputLimit) || 2,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Set Limit
|
||||
</button>
|
||||
</p>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ControlPage;
|
||||
Reference in New Issue
Block a user