DEV: Refactor initializer to use RenderGlimmer and registerWidgetShim
This commit is contained in:
parent
3828578d5d
commit
0948d6b19e
|
@ -1,40 +1,30 @@
|
||||||
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
|
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "initialize-ad-plugin",
|
name: "initialize-ad-plugin",
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
|
registerWidgetShim(
|
||||||
|
"after-post-ad",
|
||||||
|
"div.widget-connector",
|
||||||
|
hbs`<PostBottomAd @model={{@data}} />`
|
||||||
|
);
|
||||||
|
|
||||||
withPluginApi("0.1", (api) => {
|
withPluginApi("0.1", (api) => {
|
||||||
api.decorateWidget("post:after", (dec) => {
|
api.decorateWidget("post:after", (helper) => {
|
||||||
if (dec.canConnectComponent) {
|
return helper.attach("after-post-ad", helper.attrs);
|
||||||
if (!dec.attrs.cloaked) {
|
|
||||||
return dec.connect({
|
|
||||||
component: "post-bottom-ad",
|
|
||||||
context: "model",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Old way for backwards compatibility
|
|
||||||
return dec.connect({
|
|
||||||
templateName: "connectors/post-bottom/discourse-adplugin",
|
|
||||||
context: "model",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const messageBus = container.lookup("message-bus:main");
|
const messageBus = container.lookup("service:message-bus");
|
||||||
if (!messageBus) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentUser = container.lookup("service:current-user");
|
const currentUser = container.lookup("service:current-user");
|
||||||
let channel;
|
|
||||||
if (currentUser) {
|
const channel = currentUser
|
||||||
channel = "/site/house-creatives/logged-in";
|
? "/site/house-creatives/logged-in"
|
||||||
} else {
|
: "/site/house-creatives/anonymous";
|
||||||
channel = "/site/house-creatives/anonymous";
|
|
||||||
}
|
|
||||||
messageBus.subscribe(channel, function (houseAdsSettings) {
|
messageBus.subscribe(channel, function (houseAdsSettings) {
|
||||||
Site.currentProp("house_creatives", houseAdsSettings);
|
Site.currentProp("house_creatives", houseAdsSettings);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue