mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
This commit is making the following changes: - replaces `mobile-keyboard` initializer and `chat-vh` with a new template-less component: `d-vh` - ensures body scroll lock is released when page/tab focus changes - correctly locks body on chat channels and chat threads when composer is focused - removes `bodyScrollFix` as we now use body scroll lock - `onViewportResize` has been debounced to ensure it's not a bad performance vector - adds a reverse option do body scroll lock, this is made to support reversed scroll areas (like chat channels and threads) --------- Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
import { tracked } from "@glimmer/tracking";
|
|
import { action } from "@ember/object";
|
|
import { schedule } from "@ember/runloop";
|
|
import Service, { service } from "@ember/service";
|
|
import { disableBodyScroll } from "discourse/lib/body-scroll-lock";
|
|
|
|
export default class ChatThreadComposer extends Service {
|
|
@service chat;
|
|
@service capabilities;
|
|
@service appEvents;
|
|
|
|
@tracked textarea;
|
|
@tracked scrollable;
|
|
|
|
init() {
|
|
super.init(...arguments);
|
|
this.appEvents.on("discourse:focus-changed", this, this.blur);
|
|
}
|
|
|
|
willDestroy() {
|
|
super.willDestroy(...arguments);
|
|
this.appEvents.off("discourse:focus-changed", this, this.blur);
|
|
}
|
|
|
|
@action
|
|
focus(options = {}) {
|
|
this.textarea?.focus(options);
|
|
|
|
schedule("afterRender", () => {
|
|
if (this.capabilities.isIOS && !this.capabilities.isIpadOS) {
|
|
disableBodyScroll(this.scrollable, { reverse: true });
|
|
}
|
|
});
|
|
}
|
|
|
|
@action
|
|
blur() {
|
|
this.textarea?.blur();
|
|
}
|
|
|
|
@action
|
|
edit(message) {
|
|
this.chat.activeMessage = null;
|
|
message.editing = true;
|
|
message.thread.draft = message;
|
|
this.focus({ refreshHeight: true, ensureAtEnd: true });
|
|
}
|
|
|
|
@action
|
|
replyTo() {
|
|
this.chat.activeMessage = null;
|
|
}
|
|
}
|