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-mobile.js
Joffrey JAFFEUX 07e1b0591f
REFACTOR: chat-msgactions (#18969)
- s/chat-msg-actions/chat-message-actions
- s/chat-msgactions-hover/chat-message-actions-container
- creates dedicated css files for this component
- removes useless code
- removes grayscale
2022-11-10 15:08:14 +01:00

67 lines
1.4 KiB
JavaScript

import Component from "@ember/component";
import discourseLater from "discourse-common/lib/later";
import { action } from "@ember/object";
import { isTesting } from "discourse-common/config/environment";
export default Component.extend({
tagName: "",
hasExpandedReply: false,
messageActions: null,
didInsertElement() {
this._super(...arguments);
discourseLater(this._addFadeIn);
if (this.capabilities.canVibrate && !isTesting()) {
navigator.vibrate(5);
}
},
@action
expandReply(event) {
event.stopPropagation();
this.set("hasExpandedReply", true);
},
@action
collapseMenu(event) {
event.stopPropagation();
this.onCloseMenu();
},
@action
actAndCloseMenu(fn) {
fn?.();
this.onCloseMenu();
},
onCloseMenu() {
this._removeFadeIn();
// we don't want to remove the component right away as it's animating
// 200 is equal to the duration of the css animation
discourseLater(() => {
if (this.isDestroying || this.isDestroyed) {
return;
}
// by ensuring we are not hovering any message anymore
// we also ensure the menu is fully removed
this.onHoverMessage?.(null);
}, 200);
},
_addFadeIn() {
document
.querySelector(".chat-message-actions-backdrop")
?.classList.add("fade-in");
},
_removeFadeIn() {
document
.querySelector(".chat-message-actions-backdrop")
?.classList?.remove("fade-in");
},
});