From c6e74cca90c853beb44f02592fec6897324925ce Mon Sep 17 00:00:00 2001 From: Sergo Date: Sun, 4 Feb 2024 01:48:14 +0200 Subject: [PATCH] add card-style template for mobile view --- public/index.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/public/index.js b/public/index.js index cf7c374..59389b7 100644 --- a/public/index.js +++ b/public/index.js @@ -1,8 +1,10 @@ function renderAliases(data) { const dataContainer = document.getElementById('container'); - const template = Handlebars.compile(okHandlebarsTemplate); + const template = window.innerWidth > 768 ? Handlebars.compile(defaultTemplate) : Handlebars.compile(responsiveCardTemplate); const html = template({ - data: data.sort((a, b) => new Date(a.created) - new Date(b.created)) + data: data + .sort((a, b) => new Date(a.created) - new Date(b.created)) + .map(alias => ({ ...alias, created: new Date(alias.created).toLocaleString() })) }); dataContainer.innerHTML = html; @@ -38,7 +40,7 @@ function copyToClipboard(text) { navigator.clipboard.writeText(text) } -const okHandlebarsTemplate = ` +const defaultTemplate = ` @@ -64,6 +66,29 @@ const okHandlebarsTemplate = `
Create alias
` +// Responsive card template for mobile +const responsiveCardTemplate = ` + {{#each data}} +
+
+
+ {{#each tags}} + {{this}} + {{/each}} +
+
{{address}}
+

{{created}}

+
Delete
+
+
+ {{/each}} + +