From a226c8ff72033cbde295c07ab565bedf0391b702 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 31 Jan 2023 12:00:26 +0000 Subject: [PATCH] Frontend: Add common vibrate function Signed-off-by: Fred Boniface --- static/index.html | 2 +- static/js/find-code.js | 3 +++ static/js/issue.js | 3 ++- static/js/lib.main.js | 10 ++++++++++ static/sw.js | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/static/index.html b/static/index.html index 3e8281b..b8ba474 100644 --- a/static/index.html +++ b/static/index.html @@ -62,7 +62,7 @@ diff --git a/static/js/find-code.js b/static/js/find-code.js index e599133..5af161f 100644 --- a/static/js/find-code.js +++ b/static/js/find-code.js @@ -38,6 +38,7 @@ async function parseData(values){ log("find-code.parseData: No data entered", "WARN") await clearForm(); document.getElementById("name").value = "No data entered" + vibrate("err"); hideLoading(); return; } @@ -52,6 +53,7 @@ async function getData(type, value){ return await resp.json() } catch (err) { log(`find-code.getData: Error getting data: ${err}`, "WARN") + vibrate("err") return ""; } } @@ -88,5 +90,6 @@ async function clearForm(){ document.getElementById("nlc").value = "" document.getElementById("tiploc").value = "" document.getElementById("stanox").value = "" + navigator.vibrate("ok"); hideLoading(); } \ No newline at end of file diff --git a/static/js/issue.js b/static/js/issue.js index 162a100..1cac7a2 100644 --- a/static/js/issue.js +++ b/static/js/issue.js @@ -75,11 +75,12 @@ async function send() { var res = await fetch("/api/v1/issue", opt) if (res.status == 200) { setLoadingDesc("Success") + vibrate("ok") await delay(2500) window.location.replace("/") } else { setLoadingDesc("Error") - navigator.vibrate(1500) + vibrate("err") await delay(2500) hideLoading() document.getElementById("preflight").style = "display: none;" diff --git a/static/js/lib.main.js b/static/js/lib.main.js index fe5dfb6..4865684 100644 --- a/static/js/lib.main.js +++ b/static/js/lib.main.js @@ -112,4 +112,14 @@ async function getQuery(param) { } else { return 'false' } +} + +async function vibrate(type) { + vb = navigator.vibrate + switch (type) { + case "err": + vb(1200) + case "ok": + vb([100,30,100]) + } } \ No newline at end of file diff --git a/static/sw.js b/static/sw.js index b05fb96..4cef8f0 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,6 +1,6 @@ /* Service Worker */ -const appVersion = "0.0.1-dev-20230127001" +const appVersion = "0.0.1-dev-2023013104" const cacheName = `owlboard-${appVersion}` const cacheIDs = [cacheName] const cacheFiles = [