This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.js
Joffrey JAFFEUX 66130dc8c1
REFACTOR: handles every chat resource as an URL (#18961)
- Note this is also tweaking the UI a little bit as we are now using links/buttons in the header as needed
- It disables the find ideal channel in drawer mode, if loading `/chat` in drawer mode it will either reopen at the last position or just stay on index
2022-11-11 06:39:15 +01:00

58 lines
1.5 KiB
JavaScript

import Component from "@ember/component";
import { action } from "@ember/object";
import { createPopper } from "@popperjs/core";
import { schedule } from "@ember/runloop";
import { inject as service } from "@ember/service";
const MSG_ACTIONS_HORIZONTAL_PADDING = 2;
const MSG_ACTIONS_VERTICAL_PADDING = -15;
export default Component.extend({
tagName: "",
chatStateManager: service(),
messageActions: null,
didReceiveAttrs() {
this._super(...arguments);
this.popper?.destroy();
schedule("afterRender", () => {
this.popper = createPopper(
document.querySelector(
`.chat-message-container[data-id="${this.message.id}"]`
),
document.querySelector(
`.chat-message-actions-container[data-id="${this.message.id}"] .chat-message-actions`
),
{
placement: "right-start",
modifiers: [
{ name: "hide", enabled: true },
{
name: "offset",
options: {
offset: ({ popper, placement }) => {
return [
MSG_ACTIONS_VERTICAL_PADDING,
-(placement.includes("left") || placement.includes("right")
? popper.width + MSG_ACTIONS_HORIZONTAL_PADDING
: popper.height),
];
},
},
},
],
}
);
});
},
@action
handleSecondaryButtons(id) {
this.messageActions?.[id]?.();
},
});