add utils page to reset data and load game config
This commit is contained in:
parent
0668895422
commit
b7e43f3526
55
src/app/utils/page.tsx
Normal file
55
src/app/utils/page.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import Navbar from "../Components/Navigation/Navbar";
|
||||
|
||||
const allowedUserID = ["30f76186-83ff-4b26-a429-357bc1ee126f"];
|
||||
|
||||
export default function Utils() {
|
||||
const [userId, setUserId] = useState<string>("");
|
||||
|
||||
const clearUserData = async () => {
|
||||
await fetch(`/api/user/${userId}/clear-data`, {
|
||||
method: "POST",
|
||||
});
|
||||
};
|
||||
|
||||
const loadConfig = async () => {
|
||||
await fetch(`/api/import-config`, {
|
||||
method: "POST",
|
||||
});
|
||||
};
|
||||
|
||||
if (allowedUserID.indexOf(userId) == -1) {
|
||||
return (
|
||||
<>
|
||||
<Navbar setUserId={setUserId} />
|
||||
<h1 className="text-2xl text-white p-8">Missing Permission</h1>;
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-8">
|
||||
<Navbar setUserId={setUserId} />
|
||||
<h1 className="text-2xl text-white mb-4">Utilities</h1>
|
||||
<button
|
||||
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold w-auto text-center mr-4"
|
||||
onClick={() => {
|
||||
clearUserData();
|
||||
}}
|
||||
>
|
||||
Clear My Data
|
||||
</button>
|
||||
<button
|
||||
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold w-auto text-center mr-4"
|
||||
onClick={() => {
|
||||
loadConfig();
|
||||
}}
|
||||
>
|
||||
Load Game Config
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -6,10 +6,11 @@ export default async function handler(
|
||||
res: NextApiResponse
|
||||
) {
|
||||
try {
|
||||
console.log("Loading config...")
|
||||
if (req.method === "POST") {
|
||||
const db = postgresConnection;
|
||||
const result = await db.query("select import_config();");
|
||||
|
||||
console.log(result)
|
||||
if (result.rowCount > 0) {
|
||||
return res.status(200).json({ userId: result.rows[0].id});
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user