mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 18:44:38 +08:00
FEATURE: allows to define a dissmiss duration on global notices (#8715)
This commit also adds more documentation to various options and defines a 1 week duration for IE global notice dismiss duration.
This commit is contained in:
parent
ec1aeb8a55
commit
f4744193bd
@ -9,7 +9,7 @@ export function addGlobalNotice(text, id, options = {}) {
|
|||||||
_pluginNotices.push(Notice.create({ text, id, options }));
|
_pluginNotices.push(Notice.create({ text, id, options }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const GLOBAL_NOTICE_DISMISSED_PROMPT_KEY = "dismissed-global-notice";
|
const GLOBAL_NOTICE_DISMISSED_PROMPT_KEY = "dismissed-global-notice-v2";
|
||||||
|
|
||||||
const Notice = EmberObject.extend({
|
const Notice = EmberObject.extend({
|
||||||
text: null,
|
text: null,
|
||||||
@ -20,12 +20,20 @@ const Notice = EmberObject.extend({
|
|||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
|
// can this banner be hidden
|
||||||
dismissable: false,
|
dismissable: false,
|
||||||
|
// prepend html content
|
||||||
html: null,
|
html: null,
|
||||||
|
// will define the style of the banner, follows alerts styling
|
||||||
level: "info",
|
level: "info",
|
||||||
|
// should the banner be permanently hidden?
|
||||||
persistentDismiss: true,
|
persistentDismiss: true,
|
||||||
|
// callback function when dismissing a banner
|
||||||
onDismiss: null,
|
onDismiss: null,
|
||||||
visibility: null
|
// show/hide banner function, will take precedence over everything
|
||||||
|
visibility: null,
|
||||||
|
// how long before banner should show again, eg: moment.duration(1, "week")
|
||||||
|
dismissDuration: null
|
||||||
};
|
};
|
||||||
|
|
||||||
this.options = this.set(
|
this.options = this.set(
|
||||||
@ -145,7 +153,24 @@ export default Component.extend({
|
|||||||
return notice.options.visibility(notice);
|
return notice.options.visibility(notice);
|
||||||
} else {
|
} else {
|
||||||
const key = `${GLOBAL_NOTICE_DISMISSED_PROMPT_KEY}-${notice.id}`;
|
const key = `${GLOBAL_NOTICE_DISMISSED_PROMPT_KEY}-${notice.id}`;
|
||||||
return !this.keyValueStore.get(key);
|
const value = this.keyValueStore.get(key);
|
||||||
|
|
||||||
|
// banner has never been dismissed
|
||||||
|
if (!value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// banner has no persistent dismiss and should always show on load
|
||||||
|
if (!notice.options.persistentDismiss) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notice.options.dismissDuration) {
|
||||||
|
const resetAt = moment(value).add(notice.options.dismissDuration);
|
||||||
|
return moment().isAfter(resetAt);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -160,7 +185,7 @@ export default Component.extend({
|
|||||||
if (notice.options.persistentDismiss) {
|
if (notice.options.persistentDismiss) {
|
||||||
this.keyValueStore.set({
|
this.keyValueStore.set({
|
||||||
key: `${GLOBAL_NOTICE_DISMISSED_PROMPT_KEY}-${notice.id}`,
|
key: `${GLOBAL_NOTICE_DISMISSED_PROMPT_KEY}-${notice.id}`,
|
||||||
value: true
|
value: moment().toISOString(true)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ function initializeInternetExplorerDeprecation(api) {
|
|||||||
api.addGlobalNotice(
|
api.addGlobalNotice(
|
||||||
I18n.t("discourse_internet_explorer.deprecation_warning"),
|
I18n.t("discourse_internet_explorer.deprecation_warning"),
|
||||||
"deprecate-internet-explorer",
|
"deprecate-internet-explorer",
|
||||||
{ dismissable: true }
|
{ dismissable: true, dismissDuration: moment.duration(1, "week") }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user