-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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 /> | ||
|
@@ -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> | ||
); | ||
} | ||
|