Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensures chat panel can't have an invalid width (#27876)

Joffrey JAFFEUX897518e874ad
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-side-panel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-side-panel.gjs
index 52cb3128cbd..978fd535a5d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-side-panel.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-side-panel.gjs
@@ -1,47 +1,65 @@
import Component from "@glimmer/component";
-import { tracked } from "@glimmer/tracking";
import { hash } from "@ember/helper";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { service } from "@ember/service";
-import { htmlSafe } from "@ember/template";
-import { and } from "truth-helpers";
+import KeyValueStore from "discourse/lib/key-value-store";
import resizableNode from "../modifiers/chat/resizable-node";
import ChatSidePanelResizer from "./chat-side-panel-resizer";
-const MIN_CHAT_CHANNEL_WIDTH = 250;
+const MIN_PANEL_WIDTH = 250;
+const STORE_NAMESPACE = "discourse_chat_side_panel_size_";
export default class ChatSidePanel extends Component {
@service chatStateManager;
- @service chatSidePanelSize;
@service site;
- @tracked widthStyle;
+ store = new KeyValueStore(STORE_NAMESPACE);
@action
- setupSize() {
- this.widthStyle = htmlSafe(`width:${this.chatSidePanelSize.width}px`);
- }
+ setupSize(element) {
+ if (this.site.mobileView) {
+ return;
+ }
- @action
- didResize(element, size) {
- if (this.isDestroying || this.isDestroyed) {
+ if (!this.chatStateManager.isFullPageActive) {
return;
}
- const parentWidth = element.parentElement.getBoundingClientRect().width;
- const mainPanelWidth = parentWidth - size.width;
+ const validWidth = Math.min(
+ this.store.getObject("width"),
+ this.mainContainerWidth - MIN_PANEL_WIDTH
+ );
+
+ element.animate(
+ [{ width: element.style.width }, { width: validWidth + "px" }],
+ { duration: 0, fill: "forwards" }
+ );
+ this.storeWidth(validWidth);
+ }
- if (mainPanelWidth >= MIN_CHAT_CHANNEL_WIDTH) {
- this.chatSidePanelSize.width = size.width;
- element.style.width = size.width + "px";
- this.widthStyle = htmlSafe(`width:${size.width}px`);
+ @action
+ didResize(element, size) {
+ const mainPanelWidth = this.mainContainerWidth - size.width;
+
+ if (size.width >= MIN_PANEL_WIDTH && mainPanelWidth >= MIN_PANEL_WIDTH) {
+ element.animate(
+ [{ width: element.style.width }, { width: size.width + "px" }],
+ { duration: 0, fill: "forwards" }
+ );
+ this.storeWidth(size.width);
}
}
- #maxWidth(element) {
- const parentWidth = element.parentElement.getBoundingClientRect().width;
- return parentWidth - MIN_CHAT_CHANNEL_WIDTH;
+ get mainContainerWidth() {
+ return document.getElementById("main-chat-outlet").clientWidth;
+ }
+
+ storeWidth(width) {
+ this.store.setObject({
+ key: "width",
+ value: width,
+ });
}
<template>
@@ -56,10 +74,6 @@ export default class ChatSidePanel extends Component {
position=false vertical=false mutate=false resetOnWindowResize=true
)
}}
- style={{if
- (and this.site.desktopView this.chatStateManager.isFullPageActive)
- this.widthStyle
- }}
>
{{yield}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
index e92e082e5e1..a3cac9fef9f 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel.gjs
@@ -1,7 +1,7 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import Navbar from "discourse/plugins/chat/discourse/components/chat/navbar";
-import SidePanel from "discourse/plugins/chat/discourse/components/chat-side-panel";
+import ChatSidePanel from "discourse/plugins/chat/discourse/components/chat-side-panel";
import FullPageChat from "discourse/plugins/chat/discourse/components/full-page-chat";
export default class ChatRoutesChannel extends Component {
@@ -32,8 +32,8 @@ export default class ChatRoutesChannel extends Component {
/>
</div>
- <SidePanel>
+ <ChatSidePanel>
{{outlet}}
- </SidePanel>
+ </ChatSidePanel>
</template>
}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-side-panel-size.js b/plugins/chat/assets/javascripts/discourse/services/chat-side-panel-size.js
deleted file mode 100644
index e09e354fc67..00000000000
--- a/plugins/chat/assets/javascripts/discourse/services/chat-side-panel-size.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import Service from "@ember/service";
-import KeyValueStore from "discourse/lib/key-value-store";
-
-export default class ChatSidePanelSize extends Service {
- STORE_NAMESPACE = "discourse_chat_side_panel_size_";
- MIN_WIDTH = 250;
-
- store = new KeyValueStore(this.STORE_NAMESPACE);
-
- get width() {
- return this.store.getObject("width") || this.MIN_WIDTH;
- }
-
- set width(width) {
- this.store.setObject({
- key: "width",
- value: this.#min(width, this.MIN_WIDTH),
- });
- }
-
- #min(number, min) {
- return Math.max(number, min);
- }
-}
diff --git a/plugins/chat/assets/stylesheets/common/base-common.scss b/plugins/chat/assets/stylesheets/common/base-common.scss
index 5a2fb54c01e..04c16a2eb5d 100644
--- a/plugins/chat/assets/stylesheets/common/base-common.scss
+++ b/plugins/chat/assets/stylesheets/common/base-common.scss
@@ -267,6 +267,7 @@ html.has-full-page-chat {
.main-chat-outlet {
min-height: 0;
max-width: 100vw;
+ box-sizing: border-box;
}
}
}
diff --git a/plugins/chat/assets/stylesheets/common/chat-notices.scss b/plugins/chat/assets/stylesheets/common/chat-notices.scss
index fc313ac3ec7..13ba29ba101 100644
--- a/plugins/chat/assets/stylesheets/common/chat-notices.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-notices.scss
@@ -24,6 +24,7 @@
margin-left: auto;
margin-right: auto;
gap: 0.25rem;
+ box-sizing: border-box;
}
.dismiss-btn {