DEV: Tweaks for drop-down implementation (#69)
- Remove unused 'toggleAiBotPanel' widget action - Switch from appEvents to closure actions - Convert widget definition to native class syntax, so that we can use `@action` decorator. (alternatively, we could have done `{ closePanel: this.hideAiBotPanel.bind(this) }` in `RenderGlimmer`
This commit is contained in:
parent
deb34bb52f
commit
261fe13599
|
@ -8,7 +8,6 @@ import I18n from "I18n";
|
||||||
export default class AiBotHeaderPanel extends Component {
|
export default class AiBotHeaderPanel extends Component {
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
@service composer;
|
@service composer;
|
||||||
@service appEvents;
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async composeMessageWithTargetBot(target) {
|
async composeMessageWithTargetBot(target) {
|
||||||
|
@ -29,6 +28,7 @@ export default class AiBotHeaderPanel extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
async #composeAiBotMessage(targetBot) {
|
async #composeAiBotMessage(targetBot) {
|
||||||
composeAiBotMessage(targetBot, this.composer, this.appEvents);
|
this.args.closePanel();
|
||||||
|
composeAiBotMessage(targetBot, this.composer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,7 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import Composer from "discourse/models/composer";
|
import Composer from "discourse/models/composer";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
export async function composeAiBotMessage(targetBot, composer, appEvents) {
|
export async function composeAiBotMessage(targetBot, composer) {
|
||||||
if (appEvents) {
|
|
||||||
appEvents.trigger("ai-bot-menu:close");
|
|
||||||
}
|
|
||||||
let botUsername = await ajax("/discourse-ai/ai-bot/bot-username", {
|
let botUsername = await ajax("/discourse-ai/ai-bot/bot-username", {
|
||||||
data: { username: targetBot },
|
data: { username: targetBot },
|
||||||
}).then((data) => {
|
}).then((data) => {
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
import { createWidget } from "discourse/widgets/widget";
|
import Widget from "discourse/widgets/widget";
|
||||||
import RenderGlimmer from "discourse/widgets/render-glimmer";
|
import RenderGlimmer from "discourse/widgets/render-glimmer";
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
export default createWidget("ai-bot-header-panel-wrapper", {
|
export default class AiBotHeaderPanelWrapper extends Widget {
|
||||||
buildAttributes() {
|
buildAttributes() {
|
||||||
return { "data-click-outside": true };
|
return { "data-click-outside": true };
|
||||||
},
|
}
|
||||||
|
|
||||||
html() {
|
html() {
|
||||||
return [
|
return [
|
||||||
new RenderGlimmer(
|
new RenderGlimmer(
|
||||||
this,
|
this,
|
||||||
"div.widget-component-connector",
|
"div.widget-component-connector",
|
||||||
hbs`<AiBotHeaderPanel />`
|
hbs`<AiBotHeaderPanel @closePanel={{@data.closePanel}} />`,
|
||||||
|
{ closePanel: this.closePanel }
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
},
|
}
|
||||||
|
|
||||||
init() {
|
@action
|
||||||
this.appEvents.on("ai-bot-menu:close", this, this.clickOutside);
|
closePanel() {
|
||||||
},
|
|
||||||
|
|
||||||
destroy() {
|
|
||||||
this.appEvents.off("ai-bot-menu:close", this, this.clickOutside);
|
|
||||||
},
|
|
||||||
|
|
||||||
clickOutside() {
|
|
||||||
this.sendWidgetAction("hideAiBotPanel");
|
this.sendWidgetAction("hideAiBotPanel");
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
@action
|
||||||
|
clickOutside() {
|
||||||
|
this.closePanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@ function attachHeaderIcon(api) {
|
||||||
this.state.botSelectorVisible = false;
|
this.state.botSelectorVisible = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
api.attachWidgetAction("header", "toggleAiBotPanel", function () {
|
|
||||||
this.state.botSelectorVisible = !this.state.botSelectorVisible;
|
|
||||||
});
|
|
||||||
|
|
||||||
api.decorateWidget("header-icons:before", (helper) => {
|
api.decorateWidget("header-icons:before", (helper) => {
|
||||||
return helper.attach("header-dropdown", {
|
return helper.attach("header-dropdown", {
|
||||||
title: "blog.start_gpt_chat",
|
title: "blog.start_gpt_chat",
|
||||||
|
|
Loading…
Reference in New Issue