mobile: fix mobile view

This uses `dvh` and `dvw` rather than `vh` and `vw`, which excludes
things like the address bar and the keyboard.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2023-12-03 19:35:34 +08:00
parent efe0397fab
commit 4ff0642139
6 changed files with 70 additions and 16 deletions

View File

@ -48,11 +48,11 @@ function getTasks(_request: Request, response: Response) {
function getVoltages(_request: Request, response: Response) { function getVoltages(_request: Request, response: Response) {
var voltages: { [key: string]: number } = { var voltages: { [key: string]: number } = {
'3.3V': 3.3, 'system': 3.3 + Math.random() * 0.1 - 0.05,
'Target': 1.8, 'target': 1.8 + Math.random() * 0.1 - 0.05,
'USB': 5.02, 'usb': 5.0 + Math.random() * 0.1 - 0.05,
'Debug': 5.01, 'debug': 5.0 + Math.random() * 0.1 - 0.05,
'EXT': 3.7, 'ext': 3.7 + Math.random() * 0.1 - 0.05,
}; };
response.send(voltages); response.send(voltages);
} }

View File

@ -53,6 +53,15 @@ function setupNavItem(widget: FarpatchWidget) {
}, false); }, false);
} }
// export function resizeViewport() {
// // First we get the viewport height and we multiple it by 1% to get a value for a vh unit
// let vh = window.innerHeight * 0.01;
// // Then we set the value in the --vh custom property to the root of the document
// document.documentElement.style.setProperty('--vh', `${vh}px`);
// }
// document.addEventListener('resize', resizeViewport, false);
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// Populate the page // Populate the page
var body = document.getElementsByTagName("body")[0]; var body = document.getElementsByTagName("body")[0];
@ -108,4 +117,6 @@ document.addEventListener('DOMContentLoaded', function () {
currentWidget = farpatchWidgets[0]; currentWidget = farpatchWidgets[0];
activateWidget(farpatchWidgets[0]); activateWidget(farpatchWidgets[0]);
// resizeViewport();
}, false); }, false);

View File

@ -1,5 +1,7 @@
import { FarpatchWidget, makeNavView as makeNavItem } from "../interfaces"; import { FarpatchWidget, makeNavView as makeNavItem } from "../interfaces";
var DASHBOARD_UPDATE_TIMER: number | null = null;
class DashboardItem { class DashboardItem {
id: string; id: string;
name: string; name: string;
@ -19,6 +21,7 @@ class DashboardItem {
var itemValue: HTMLElement = document.createElement("span"); var itemValue: HTMLElement = document.createElement("span");
itemValue.classList.add("dashboard-item-value"); itemValue.classList.add("dashboard-item-value");
itemValue.id = 'dashboard-item-value-' + this.id;
itemValue.innerHTML = this.value; itemValue.innerHTML = this.value;
field.appendChild(itemTitle); field.appendChild(itemTitle);
@ -80,7 +83,7 @@ export class DashboardWidget implements FarpatchWidget {
new DashboardItem("system-voltage", "System", "3.3V"), new DashboardItem("system-voltage", "System", "3.3V"),
new DashboardItem("target-voltage", "Target", "1.8V"), new DashboardItem("target-voltage", "Target", "1.8V"),
new DashboardItem("usb-voltage", "USB", "5.0V"), new DashboardItem("usb-voltage", "USB", "5.0V"),
new DashboardItem("extra-voltage", "Extra", "3.8V"), new DashboardItem("ext-voltage", "Extra", "3.8V"),
]), ]),
new DashboardSection("network", "Network", [ new DashboardSection("network", "Network", [
new DashboardItem("ip-address", "IP Address", "10.0.0.5"), new DashboardItem("ip-address", "IP Address", "10.0.0.5"),
@ -115,10 +118,44 @@ export class DashboardWidget implements FarpatchWidget {
onFocus(element: HTMLElement): void { onFocus(element: HTMLElement): void {
console.log("Displaying Dashboard Widget"); console.log("Displaying Dashboard Widget");
element.appendChild(this.view); element.appendChild(this.view);
DASHBOARD_UPDATE_TIMER = window.setInterval(() => {
console.log("Updating Dashboard Widget");
fetch("/fp/voltages").then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
response.json().then((json) => {
if (!json) {
throw new Error("Response was not JSON");
}
var voltage_fields = [
"system",
"target",
"usb",
"debug",
"ext",
];
for (var i = 0; i < voltage_fields.length; i++) {
var field = document.getElementById("dashboard-item-value-" + voltage_fields[i] + "-voltage");
var voltage = json[voltage_fields[i]];
if (field && typeof voltage === "number") {
field.innerText = voltage.toPrecision(3) + "V";
}
}
});
})
}, 1000);
} }
onBlur(element: HTMLElement): void { onBlur(element: HTMLElement): void {
console.log("Archiving Dashboard Widget"); console.log("Archiving Dashboard Widget");
element.removeChild(this.view); element.removeChild(this.view);
if (DASHBOARD_UPDATE_TIMER !== null) {
window.clearInterval(DASHBOARD_UPDATE_TIMER);
DASHBOARD_UPDATE_TIMER = null;
}
} }
} }

View File

@ -51,7 +51,7 @@ main {
padding: 0rem; padding: 0rem;
/* SIDEBAR WIDTH */ /* SIDEBAR WIDTH */
margin-left: 10rem; margin-left: 10rem;
height: 100vh; height: 100dvh;
transition: margin-left 500ms ease; transition: margin-left 500ms ease;
} }
@ -63,7 +63,7 @@ main {
.main-content { .main-content {
display: none; display: none;
height: 100vh; height: 100dvh;
} }
.main-content-active { .main-content-active {
@ -76,7 +76,7 @@ main {
width: 10rem; width: 10rem;
left: 0; left: 0;
background-color: white; background-color: white;
height: 100vh; height: 100dvh;
transition: width 500ms ease; transition: width 500ms ease;
overflow: overlay; overflow: overlay;
} }
@ -92,7 +92,7 @@ main {
margin: 0; margin: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100vh; height: 100dvh;
} }
.sidenav-item { .sidenav-item {
@ -144,7 +144,7 @@ main {
} }
.dashboard-view { .dashboard-view {
max-width: 89vw; max-width: 89dvw;
padding-left: 1rem; padding-left: 1rem;
padding-right: 1rem; padding-right: 1rem;
display: grid; display: grid;

View File

@ -1,23 +1,28 @@
/* Small screen */ /* Small screen */
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {
main { main {
/* BOTTOM BAR HEIGHT */ height: calc(100dvh - 5rem);
height: calc(100vh - 5rem); /* height: calc(calc(var(--vh, 1dvh) * 100) - 5rem); */
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.main-content { .main-content {
height: calc(100vh - 5rem); height: calc(100dvh - 5rem);
/* height: calc(calc(var(--vh, 1dvh) * 100) - 5rem); */
} }
.main-sidebar-rail { .main-sidebar-rail {
margin-left: 0; margin-left: 0;
} }
.dashboard-view {
padding-top: 1rem;
}
.sidenav { .sidenav {
bottom: 0; bottom: 0;
width: 100vw; width: 100dvw;
/* BOTTOM BAR HEIGHT */ /* BOTTOM BAR HEIGHT */
height: 5rem; height: 5rem;
align-items: flex-start; align-items: flex-start;
@ -26,7 +31,7 @@
} }
.sidenav-rail { .sidenav-rail {
width: 100vw; width: 100dvw;
transition: none; transition: none;
} }

View File

@ -35,6 +35,7 @@ module.exports = {
path: path.resolve(__dirname, OUTPUT), path: path.resolve(__dirname, OUTPUT),
}, },
devServer: { devServer: {
allowedHosts: 'all',
static: { static: {
directory: path.resolve(__dirname, OUTPUT), directory: path.resolve(__dirname, OUTPUT),
}, },