From 6e0e1dd31c6207297e345c7bc6e0f7a0c8185193 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Wed, 20 Jan 2021 11:32:21 +0100 Subject: [PATCH] Day markers --- package-lock.json | 11 +++++++++++ package.json | 1 + src/assets/css/chat.scss | 34 ++++++++++++++++++++++++++++++++-- src/components/Chat.vue | 17 +++++++++++++++++ src/plugins/utils.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b3ff21..36b1aa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "aes-js": "^3.1.2", "axios": "^0.21.0", "core-js": "^3.6.5", + "dayjs": "^1.10.3", "intersection-observer": "^0.11.0", "js-sha256": "^0.9.0", "json-web-key": "^0.4.0", @@ -4711,6 +4712,11 @@ "node": ">=0.10" } }, + "node_modules/dayjs": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.3.tgz", + "integrity": "sha512-/2fdLN987N8Ki7Id8BUN2nhuiRyxTLumQnSQf9CNncFCyqFsSKb9TNhzRYcC8K8eJSJOKvbvkImo/MKKhNi4iw==" + }, "node_modules/de-indent": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz", @@ -18630,6 +18636,11 @@ "assert-plus": "^1.0.0" } }, + "dayjs": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.3.tgz", + "integrity": "sha512-/2fdLN987N8Ki7Id8BUN2nhuiRyxTLumQnSQf9CNncFCyqFsSKb9TNhzRYcC8K8eJSJOKvbvkImo/MKKhNi4iw==" + }, "de-indent": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz", diff --git a/package.json b/package.json index 8ae2380..dcbce79 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "aes-js": "^3.1.2", "axios": "^0.21.0", "core-js": "^3.6.5", + "dayjs": "^1.10.3", "intersection-observer": "^0.11.0", "js-sha256": "^0.9.0", "json-web-key": "^0.4.0", diff --git a/src/assets/css/chat.scss b/src/assets/css/chat.scss index 0e2ce90..7deefd2 100644 --- a/src/assets/css/chat.scss +++ b/src/assets/css/chat.scss @@ -383,13 +383,13 @@ $admin-fg: white; margin-left: 20px; margin-right: 20px; height: 1px; - width: 100%; + width: calc(100% - 40px); line-height: var(--v-theme-title-featured-line-height); position: absolute; bottom: 0; font-family: sans-serif; font-style: normal; - font-weight: bold; + font-weight: normal; font-size: 8 * $chat-text-size; line-height: 140%; /* identical to box height, or 14px */ @@ -401,8 +401,38 @@ $admin-fg: white; position: absolute; top: -4px; background: white; + transform: translate(-50%,0); padding-left: 4px; padding-right: 4px; content: attr(title); } +} + +.day-marker { + margin-left: 20px; + margin-right: 20px; + margin-top: 20px; + margin-bottom: 20px; + height: 1px; + line-height: var(--v-theme-title-featured-line-height); + font-family: sans-serif; + font-style: normal; + font-weight: normal; + font-size: 10 * $chat-text-size; + line-height: 140%; + /* identical to box height, or 14px */ + letter-spacing: 0.29px; + color: black; + background-color: black; + text-align: center; + position: relative; + &::after { + position: absolute; + top: -8px; + background: white; + transform: translate(-50%,0); + padding-left: 10px; + padding-right: 10px; + content: attr(title); + } } \ No newline at end of file diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 5b856d3..7dbeb0f 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -29,6 +29,10 @@ />
+ + +
+
{ @@ -415,6 +420,32 @@ class Util { }) } + + /** + * Return number of whole days between the timestamps, at end of that day. + * @param {*} ts1 + * @param {*} ts2 + */ + dayDiff(ts1, ts2) { + var t1 = dayjs(ts1).endOf('day'); + var t2 = dayjs(ts2).endOf('day'); + return t2.diff(t1, 'day'); + } + + formatDay(timestamp) { + var then = dayjs(timestamp).endOf('day'); + var now = dayjs().endOf('day'); + const dayDiff = now.diff(then, 'day'); + if (dayDiff < 1) { + return "Today"; + } else if (dayDiff < 2) { + return "Yesterday"; + } else if (dayDiff < 7) { + return "" + dayDiff + " days ago"; + } else { + return then.format('L'); + } + } } export default new Util();