From 8ecdf023371b3caf1e898790585a99abf9e8bc4f Mon Sep 17 00:00:00 2001
From: Brendan F <EpicWolverine@users.noreply.github.com>
Date: Tue, 11 Jul 2023 00:26:19 -0700
Subject: Add stat importing

---
 src/app.tsx | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'src/app.tsx')

diff --git a/src/app.tsx b/src/app.tsx
index ac8765f..b906eab 100644
--- a/src/app.tsx
+++ b/src/app.tsx
@@ -25,6 +25,26 @@ function App() {
   const [didGuess, setDidGuess] = React.useState<boolean>(false);
 
   const firstRun = localStorage.getItem("firstRun") === null;
+
+  function importStats () {
+    const queryParam = new URLSearchParams(window.location.search).get('statsImport') || "";
+    if (queryParam){
+      const importedStats = JSON.parse(queryParam)
+      if (Array.isArray(importedStats)) {
+        importedStats.forEach(day => {
+          if (Array.isArray(day.guesses)) {
+            if(day.guesses.length == 5){
+              day.guesses.push(initialGuess)
+            }
+          }
+        });
+      }
+      localStorage.setItem("stats", JSON.stringify(importedStats));
+      location.replace(location.pathname);
+    }
+  }
+  importStats()
+
   let stats = JSON.parse(localStorage.getItem("stats") || "{}");
 
   React.useEffect(() => {
-- 
cgit v1.2.3

