Change the way notification items are created

Look for the specialised version first, before falling back to the
default. This allows the behaviour to be customised based on the type of
notification.
This commit is contained in:
Daniel Waterworth 2019-06-07 06:41:12 +01:00 committed by Robin Ward
parent cdf0cd3ecd
commit 04a75b1cb3
2 changed files with 22 additions and 4 deletions

View File

@ -12,8 +12,16 @@ createWidget("large-notification-item", {
},
html(attrs) {
const notificationName =
this.site.notificationLookup[attrs.notification_type];
const widgetNames = [
`${notificationName.replace(/_/g, '-')}-notification-item`,
"default-notification-item"
];
return [
this.attach("default-notification-item", attrs),
this.attach(widgetNames, attrs),
h("span.time", dateNode(attrs.created_at))
];
}

View File

@ -88,9 +88,19 @@ export default createWidget("user-notifications", {
if (state.loading) {
result.push(h("div.spinner-container", h("div.spinner")));
} else if (state.notifications.length) {
const notificationItems = state.notifications.map(n =>
this.attach("default-notification-item", n)
);
const notificationItems =
state.notifications.map(attrs => {
const notificationName =
this.site.notificationLookup[attrs.notification_type];
const widgetNames = [
`${notificationName.replace(/_/g, '-')}-notification-item`,
"default-notification-item"
];
return this.attach(widgetNames, attrs);
});
result.push(h("hr"));