mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 17:33:53 +08:00
f5d391a48a
AppEvents was always a service object in disguise, so we should move it to the correct place in the application. Doing this allows other service objects to inject it easily without container access. In the future we should also deprecate `this.appEvents` without an explicit injection too.
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
function initialize(api) {
|
|
const messageBus = api.container.lookup("message-bus:main");
|
|
const currentUser = api.getCurrentUser();
|
|
const appEvents = api.container.lookup("service:app-events");
|
|
|
|
api.modifyClass("component:site-header", {
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
this.dispatch("header:search-context-trigger", "header");
|
|
}
|
|
});
|
|
|
|
api.attachWidgetAction("header", "headerSearchContextTrigger", function() {
|
|
if (this.site.mobileView) {
|
|
this.state.skipSearchContext = false;
|
|
} else {
|
|
this.state.contextEnabled = true;
|
|
this.state.searchContextType = "topic";
|
|
}
|
|
});
|
|
|
|
if (messageBus && currentUser) {
|
|
messageBus.subscribe(`/new_user_narrative/tutorial_search`, () => {
|
|
appEvents.trigger("header:search-context-trigger");
|
|
});
|
|
}
|
|
}
|
|
|
|
export default {
|
|
name: "new-user-narratve",
|
|
|
|
initialize(container) {
|
|
const siteSettings = container.lookup("site-settings:main");
|
|
if (siteSettings.discourse_narrative_bot_enabled)
|
|
withPluginApi("0.8.7", initialize);
|
|
}
|
|
};
|