Skip to content

Commit

Permalink
import-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Nov 12, 2023
1 parent 9aa022e commit fb7847d
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion pages/bantuan.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { FormEvent, useEffect, useState } from "react";
import LocalStorage from "../utils/browser";
import {
GAME_STATE_KEY,
Expand Down Expand Up @@ -46,6 +46,34 @@ export default function Debug(props: { hashed: string }) {
const mailToLink = `mailto:[email protected]?subject=Problem katla&body=${messagePrefix}%0D%0A%0D%0AKode: ${debugCode}`;
const twitterIntentLink = `https://twitter.com/messages/compose?recipient_id=82924400&text=${messagePrefix}\n\nKode: ${debugCode}`;

const confirmImport = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
// @ts-ignore
const newDebugCode = e.target.debugCode.value;
let confirmed: boolean;
if (newDebugCode === debugCode) {
confirmed = window.confirm(
"Kode yang anda masukkan sama dengan kode di perangkat ini. Apakah anda yakin ingin mengimpor?"
);
} else {
confirmed = window.confirm(
"Statistik yang ada di perangkat ini akan diganti dari statistik dari kode. Apakah anda yakin?"
);
}

if (!confirmed) return;

try {
const decoded = atob(newDebugCode).split(":");
const stats = decoded[3];
LocalStorage.setItem(GAME_STATS_KEY, stats);
alert("Statistik berhasil diimpor");
window.location.reload();
} catch (err) {
alert("Kode yang anda masukkan tidak valid");
}
};

return (
<div className="dark:text-white max-w-lg mx-auto mt-4 px-3">
<NewSiteWarning />
Expand All @@ -70,6 +98,15 @@ export default function Debug(props: { hashed: string }) {
</pre>
</>
)}
<h1 className="text-3xl mb-4">Impor Statistik</h1>
<p className="mb-4">
Masukkan debug code yang anda dapat dari halaman ini di perangkat lain
untuk mengimpor statistik dari perangkat tersebut
</p>
<form onSubmit={confirmImport}>
<textarea name="debugCode" className="w-full h-64" />
<button type="submit">Impor</button>
</form>
</div>
);
}
Expand Down

0 comments on commit fb7847d

Please sign in to comment.