diff --git a/core/assets/js/app.js b/core/assets/js/app.js index 3b895b3571..154e6d4df3 100644 --- a/core/assets/js/app.js +++ b/core/assets/js/app.js @@ -36,6 +36,7 @@ window.registerAPNSDeviceToken = registerAPNSDeviceToken; window.addEventListener("phx:page-loading-stop", (info) => { if (info.detail.kind == "initial") { TimeZone.sendToServer(); + Viewport.sendToServer(); } }); diff --git a/core/assets/js/tabbar.js b/core/assets/js/tabbar.js index eff8758db3..355fcd4367 100644 --- a/core/assets/js/tabbar.js +++ b/core/assets/js/tabbar.js @@ -2,6 +2,7 @@ let tabbarId = ""; export const Tabbar = { mounted() { + console.log("[Tabbar] mounted"); tabbarId = this.el.id; var initialTabId = this.el.dataset.initialTab @@ -21,6 +22,7 @@ export const Tabbar = { }, updated() { + console.log("[Tabbar] updated"); var savedTabId = this.loadActiveTab(); this.show(savedTabId, false); }, @@ -39,22 +41,36 @@ export const Tabbar = { }, saveActiveTab(tabId) { - console.info("saveActiveTab ", tabId); + console.info("[Tabbar] saveActiveTab ", tabId); window.localStorage.setItem(this.getActiveTabKey(), tabId); }, + getTabs() { + return document.querySelectorAll('[id^="tab_"]'); + }, + getFirstTab() { - var firstTab = document.querySelectorAll('[id^="tab_"]')[0]; - return firstTab.id; + var tabs = this.getTabs(); + console.log("tabs", tabs); + if (tabs == undefined) { + return undefined; + } else { + return tabs[0].id; + } }, show(nextTabId, scrollToTop) { + console.log("[Tabbar] nextTabId", nextTabId); + if (nextTabId == undefined) { + return; + } + this.saveActiveTab(nextTabId); var tabs = Array.from(document.querySelectorAll('[id^="tab_"]')); // Skip unknown tab if (!tabs.some((tab) => tab.id === nextTabId)) { - console.warn("Skip unknown tab", nextTabId); + console.warn("[Tabbar] Skip unknown tab", nextTabId); return; } diff --git a/core/assets/js/viewport.js b/core/assets/js/viewport.js index 57ed3f7496..a4b108e61d 100644 --- a/core/assets/js/viewport.js +++ b/core/assets/js/viewport.js @@ -4,8 +4,8 @@ let resizeHandler; export const Viewport = { mounted() { - // Direct push of current window size to properly update view - this.pushChangeEvent(); + // // Direct push of current window size to properly update view + // this.pushChangeEvent(); window.addEventListener("resize", (event) => { this.pushChangeEvent(); @@ -14,7 +14,7 @@ export const Viewport = { updated() { console.log("[Viewport] updated"); - this.pushChangeEvent(); + // this.pushChangeEvent(); }, pushChangeEvent() { @@ -28,4 +28,36 @@ export const Viewport = { turbolinksDisconnected() { window.removeEventListener("resize", resizeHandler); }, + + sendToServer() { + const viewport = { + width: window.innerWidth, + height: window.innerHeight, + }; + + console.log("[Viewport]", viewport); + + let csrfToken = document + .querySelector("meta[name='csrf-token']") + .getAttribute("content"); + + if (typeof window.localStorage != "undefined") { + try { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/api/viewport", true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.setRequestHeader("x-csrf-token", csrfToken); + xhr.onreadystatechange = function () { + console.log( + "[Veiwport] POST onreadystatechange", + this.status, + this.readyState + ); + }; + xhr.send(`{"viewport": "${viewport}"}`); + } catch (e) { + console.log("[Viewport] Error while sending viewport to server", e); + } + } + }, }; diff --git a/core/frameworks/pixel/components/tabbar.ex b/core/frameworks/pixel/components/tabbar.ex index 06aaf4415d..407469f30b 100644 --- a/core/frameworks/pixel/components/tabbar.ex +++ b/core/frameworks/pixel/components/tabbar.ex @@ -28,7 +28,6 @@ defmodule Frameworks.Pixel.Tabbar do def container(assigns) do ~H""" - <%= if Enum.count(@tabs) > 0 do %>