From 1417b6eacf54fc70f4418629ee949c98753e7d19 Mon Sep 17 00:00:00 2001
From: Nelson Chan <chakflying@hotmail.com>
Date: Mon, 6 Dec 2021 12:05:26 +0800
Subject: [PATCH 1/2] Feat: Save and restore chart period

---
 src/components/PingChart.vue | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/components/PingChart.vue b/src/components/PingChart.vue
index 4ff4c708..052afe31 100644
--- a/src/components/PingChart.vue
+++ b/src/components/PingChart.vue
@@ -228,6 +228,7 @@ export default {
                         toast.error(res.msg);
                     } else {
                         this.heartbeatList = res.data;
+                        this.$root.storage()[`chart-period-${this.monitorId}`] = newPeriod;
                     }
                     this.loading = false;
                 });
@@ -248,6 +249,12 @@ export default {
             },
             { deep: true }
         );
+
+        // Load chart period from storage if saved
+        let period = this.$root.storage()[`chart-period-${this.monitorId}`];
+        if (period != null) {
+            this.chartPeriodHrs = period;
+        }
     }
 };
 </script>

From 6f99d7577b26a45a11b5c1a3aba1fd6da1020ff0 Mon Sep 17 00:00:00 2001
From: Nelson Chan <chakflying@hotmail.com>
Date: Fri, 15 Apr 2022 03:24:58 +0800
Subject: [PATCH 2/2] Fix: Limit saved period & clear when set to recent

---
 src/components/PingChart.vue | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/components/PingChart.vue b/src/components/PingChart.vue
index 052afe31..9132b4e9 100644
--- a/src/components/PingChart.vue
+++ b/src/components/PingChart.vue
@@ -220,6 +220,7 @@ export default {
             if (newPeriod == "0") {
                 newPeriod = null;
                 this.heartbeatList = null;
+                this.$root.storage().removeItem(`chart-period-${this.monitorId}`);
             } else {
                 this.loading = true;
 
@@ -253,7 +254,7 @@ export default {
         // Load chart period from storage if saved
         let period = this.$root.storage()[`chart-period-${this.monitorId}`];
         if (period != null) {
-            this.chartPeriodHrs = period;
+            this.chartPeriodHrs = Math.min(period, 6);
         }
     }
 };