From 45c03c2b40c39e6f118c111d66b3b279564acd57 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:31:31 +0100 Subject: [PATCH 1/7] Feat: Add optional width parameter to isMobile() method --- src/mixins/mobile.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mixins/mobile.js b/src/mixins/mobile.js index c44edcff3..1f84c1bfc 100644 --- a/src/mixins/mobile.js +++ b/src/mixins/mobile.js @@ -36,8 +36,14 @@ export default { }, computed: { - isMobile() { - return this.windowWidth <= 767.98; + /** + * @param {number? | undefined} width Width of the device + * @returns {boolean} Whether the device is mobile + */ + isMobile(width) { + return (width && typeof width === "number" + ? width ?? this.windowWidth + : this.windowWidth) <= 767.98; }, }, From aae0673a3dc30319fb14351cfb48c29d8df72b03 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:34:06 +0100 Subject: [PATCH 2/7] Feat: Redirect /link to /dashboard for non-mobile users --- src/pages/List.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/List.vue b/src/pages/List.vue index dd2d46059..58b23f13b 100644 --- a/src/pages/List.vue +++ b/src/pages/List.vue @@ -6,12 +6,18 @@ <script> import MonitorList from "../components/MonitorList.vue"; +import mobile from "../mixins/mobile"; export default { components: { MonitorList, }, }; + +mobile.methods.onResize(); +if (!mobile.computed.isMobile(mobile.methods.windowWidth) && window.location.pathname === "/list") { + window.location.href = "/dashboard"; +} </script> <style lang="scss" scoped> From d4c7ebfafe2f41bda4ba7fe15e51e25ee391e7c7 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:03:09 +0100 Subject: [PATCH 3/7] Fix: Correct redirect usage --- src/pages/List.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/List.vue b/src/pages/List.vue index 58b23f13b..c24542eb7 100644 --- a/src/pages/List.vue +++ b/src/pages/List.vue @@ -12,12 +12,12 @@ export default { components: { MonitorList, }, + async mounted() { + if (!mobile.computed.isMobile()) { + this.$router.push("/dashboard"); + } + }, }; - -mobile.methods.onResize(); -if (!mobile.computed.isMobile(mobile.methods.windowWidth) && window.location.pathname === "/list") { - window.location.href = "/dashboard"; -} </script> <style lang="scss" scoped> From d64eefd70ea190b837567d919eadff68962adfea Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:04:49 +0100 Subject: [PATCH 4/7] Revert: Undo isMobile method changes --- src/mixins/mobile.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/mixins/mobile.js b/src/mixins/mobile.js index 1f84c1bfc..c44edcff3 100644 --- a/src/mixins/mobile.js +++ b/src/mixins/mobile.js @@ -36,14 +36,8 @@ export default { }, computed: { - /** - * @param {number? | undefined} width Width of the device - * @returns {boolean} Whether the device is mobile - */ - isMobile(width) { - return (width && typeof width === "number" - ? width ?? this.windowWidth - : this.windowWidth) <= 767.98; + isMobile() { + return this.windowWidth <= 767.98; }, }, From 8389f7c0541d82f06f69a1e3ab43e32110863c00 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:10:29 +0100 Subject: [PATCH 5/7] Fix: Correct mobile checking --- src/pages/List.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/List.vue b/src/pages/List.vue index c24542eb7..0cb81e262 100644 --- a/src/pages/List.vue +++ b/src/pages/List.vue @@ -13,7 +13,7 @@ export default { MonitorList, }, async mounted() { - if (!mobile.computed.isMobile()) { + if (!this.$root.isMobile) { this.$router.push("/dashboard"); } }, From 2aebf316a4cef4f89e10c2be35c657e5f9865422 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:12:39 +0100 Subject: [PATCH 6/7] Style: Remove unused variable --- src/pages/List.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/List.vue b/src/pages/List.vue index 0cb81e262..fc338347c 100644 --- a/src/pages/List.vue +++ b/src/pages/List.vue @@ -6,7 +6,6 @@ <script> import MonitorList from "../components/MonitorList.vue"; -import mobile from "../mixins/mobile"; export default { components: { From cfd20f086cf76737f93d35b6776af3d248d430e4 Mon Sep 17 00:00:00 2001 From: NihadBadalov <32594553+NihadBadalov@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:01:43 +0100 Subject: [PATCH 7/7] Feat: Move redirect logic to `onResize` --- src/mixins/mobile.js | 10 ++++++++++ src/pages/List.vue | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/mixins/mobile.js b/src/mixins/mobile.js index c44edcff3..283222ead 100644 --- a/src/mixins/mobile.js +++ b/src/mixins/mobile.js @@ -19,6 +19,16 @@ export default { onResize() { this.windowWidth = window.innerWidth; this.updateBody(); + + if (this.$router.currentRoute.value.path === "/dashboard" + || this.$router.currentRoute.value.path === "/list") { + this.$router.push({ + path: this.isMobile + ? "/list" + : "/dashboard", + query: this.$router.currentRoute.value?.query, + }); + } }, /** diff --git a/src/pages/List.vue b/src/pages/List.vue index fc338347c..dd2d46059 100644 --- a/src/pages/List.vue +++ b/src/pages/List.vue @@ -11,11 +11,6 @@ export default { components: { MonitorList, }, - async mounted() { - if (!this.$root.isMobile) { - this.$router.push("/dashboard"); - } - }, }; </script>