diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.tsx | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/app.tsx b/src/app.tsx index b906eab..32559c3 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -26,10 +26,13 @@ function App() { const firstRun = localStorage.getItem("firstRun") === null; + function reloadWithoutQueryParameters() { + location.replace(location.pathname); + } + const statsImportQueryParameter = new URLSearchParams(window.location.search).get('statsImport') || ""; function importStats () { - const queryParam = new URLSearchParams(window.location.search).get('statsImport') || ""; - if (queryParam){ - const importedStats = JSON.parse(queryParam) + if (statsImportQueryParameter){ + const importedStats = JSON.parse(statsImportQueryParameter) if (Array.isArray(importedStats)) { importedStats.forEach(day => { if (Array.isArray(day.guesses)) { @@ -40,10 +43,16 @@ function App() { }); } localStorage.setItem("stats", JSON.stringify(importedStats)); - location.replace(location.pathname); + reloadWithoutQueryParameters(); + } + } + if (statsImportQueryParameter){ + if (confirm("Do you want to import your previous stats? This will overwrite any stats on this site.")){ + importStats() + } else { + reloadWithoutQueryParameters(); } } - importStats() let stats = JSON.parse(localStorage.getItem("stats") || "{}"); |
