From 6253d7f910ddf1fe9f0b501860dd674a078996ce Mon Sep 17 00:00:00 2001 From: Rogerio Chaves Date: Wed, 8 Apr 2020 20:04:11 +0200 Subject: [PATCH] Small improvements and fix --- app/lib/express.js | 16 +++++++++------- app/public/js/index.js | 7 +++++++ app/views/profile.ejs | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/lib/express.js b/app/lib/express.js index fb97226..09d3c5d 100644 --- a/app/lib/express.js +++ b/app/lib/express.js @@ -26,17 +26,19 @@ Client(ssbSecret, ssbConfig, async (err, server) => { console.log("SSB Client ready"); }); +let profileUrl = (id, path = "") => { + if (id.includes("/")) { + return `/profile/${encodeURIComponent(id)}${path}`; + } + return `/profile/${id}${path}`; +}; + app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.set("view engine", "ejs"); app.use(express.static("public")); app.use((_req, res, next) => { - res.locals.profileUrl = (id, path = "") => { - if (id.includes("/")) { - return `/profile/${encodeURIComponent(id)}${path}`; - } - return `/profile/${id}${path}`; - }; + res.locals.profileUrl = profileUrl; res.locals.imageUrl = (blob) => { const imageHash = blob && typeof blob == "object" ? blob.link : blob; @@ -126,7 +128,7 @@ router.post("/profile/:id/publish", async (req, res) => { }); } - res.redirect("/profile/" + id); + res.redirect(profileUrl(id)); }); router.get("/pubs", async (_req, res) => { diff --git a/app/public/js/index.js b/app/public/js/index.js index 4e51ee0..cd085d6 100644 --- a/app/public/js/index.js +++ b/app/public/js/index.js @@ -1,3 +1,9 @@ +let escCallback = () => {}; +document.onkeydown = (e) => { + const isEsc = e.key === "Escape" || e.key === "Esc"; + if (isEsc) escCallback(); +}; + const messages = document.querySelectorAll(".vanishing-message"); messages.forEach((message) => { message.addEventListener("click", () => { @@ -18,5 +24,6 @@ messages.forEach((message) => { overlay.addEventListener("click", onClose); closeButton.addEventListener("click", onClose); + escCallback = onClose; }); }); diff --git a/app/views/profile.ejs b/app/views/profile.ejs index 4c5dedc..5f9dac4 100644 --- a/app/views/profile.ejs +++ b/app/views/profile.ejs @@ -27,7 +27,7 @@
" method="POST">