From c3eb18d4dcfe8ac359c802974984d0753d2078da Mon Sep 17 00:00:00 2001
From: Brendan F <EpicWolverine@users.noreply.github.com>
Date: Tue, 11 Jul 2023 21:26:46 -0700
Subject: Add confirmation before importing stats

---
 src/app.tsx | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

(limited to 'src/app.tsx')

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") || "{}");
 
-- 
cgit v1.2.3

