From 5cc48ff57ad5506e269fd45ae3b4176b0b1bef16 Mon Sep 17 00:00:00 2001 From: Nico Hagelberg Date: Sun, 16 Jun 2024 22:32:30 +0300 Subject: [PATCH] Improve infoboard view Add better formatting for human readable durations. Add filter for only viewing enabled infoboard entries. Use different styles for labels of entries that already expired. --- src/components/Infoboard.vue | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/components/Infoboard.vue b/src/components/Infoboard.vue index 42b345d..7bf2af8 100644 --- a/src/components/Infoboard.vue +++ b/src/components/Infoboard.vue @@ -45,7 +45,7 @@
-

+

Infoboard entriesAdd new infoboard entry

+ + Show enabled only +
+ Set {{ infoboard.priority }} Enabled Disabled - Set {{ infoboard.priority }} - Active until {{ formatDate(infoboard.active_until) }} ({{ formatDuration(infoboard.active_until) }}) + {{ alreadyHappend(infoboard.active_until) ? "Closed on" : "Active until" }} {{ formatDate(infoboard.active_until) }} ({{ formatDuration(infoboard.active_until) }})
{{ infoboard.body }}
@@ -160,8 +168,17 @@ export default { newInfoboard: { ...emptyEntry }, selectedEntry: { ...emptyEntry }, news: [], + showEnabledOnly: true, }; }, + computed: { + filteredInfoboards() { + if (this.showEnabledOnly) { + return this.infoboards.filter((infoboard) => infoboard.enabled); + } + return this.infoboards; + } + }, created() { // fetch the data when the view is created and the data is already being observed @@ -186,11 +203,15 @@ export default { handleError(error) { pushError(this.errors, error, this.$notify); }, + alreadyHappend(date) { + return new Date(date) < new Date(); + }, formatDate(date) { return date ? format(new Date(date), "dddd HH:mm:ss") : ""; }, formatDuration(date) { - return date ? distanceInWordsToNow(date) : ""; + const suffix = this.alreadyHappend(date) ? " ago" : " from now"; + return date ? distanceInWordsToNow(date) + suffix : ""; }, async addInfoboardEntry(entry) { if (!entry.priority || !entry.title || !entry.body) { @@ -316,4 +337,7 @@ button { .add-infoboard-entry { float: right; } +.infoboard-entry-title { + margin-bottom: 0.5rem; +}