FEATURE: decorates header-title with event date when possible (#39)

This commit is contained in:
Joffrey JAFFEUX 2020-04-29 17:58:59 +02:00 committed by GitHub
parent 166d5ff7ff
commit f601d72485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -4,13 +4,15 @@ import guessDateFormat from "discourse/plugins/discourse-calendar/lib/guess-best
function initializeDecorateTopicTitle(api) { function initializeDecorateTopicTitle(api) {
api.decorateTopicTitle((topic, node, topicTitleType) => { api.decorateTopicTitle((topic, node, topicTitleType) => {
const startsAt = topic.event_starts_at; const startsAt = topic.event_starts_at;
if (startsAt) { if (startsAt) {
const date = moment.utc(startsAt);
if (topicTitleType === "topic-list-item-title") { if (topicTitleType === "topic-list-item-title") {
if (node.querySelector(".event-date")) { if (node.querySelector(".event-date")) {
return; return;
} }
const date = moment.utc(startsAt);
const dateContainer = document.createElement("span"); const dateContainer = document.createElement("span");
dateContainer.classList.add("event-date"); dateContainer.classList.add("event-date");
dateContainer.innerText = date dateContainer.innerText = date
@ -19,6 +21,19 @@ function initializeDecorateTopicTitle(api) {
node.appendChild(dateContainer); node.appendChild(dateContainer);
} }
if (topicTitleType === "header-title") {
if (node.querySelector(".event-date")) {
return;
}
const child = document.createElement("span");
child.classList.add("event-date");
child.innerText = date
.tz(moment.tz.guess())
.format(guessDateFormat(date));
node.appendChild(child);
}
} }
}); });
} }

View File

@ -8,3 +8,14 @@
margin-left: 0.25em; margin-left: 0.25em;
} }
} }
.header-title {
.event-date {
font-size: $font-down-3;
background: $primary-low;
padding: 0.25em;
border-radius: 3px;
vertical-align: middle;
margin-left: 0.25em;
}
}