diff --git a/app/assets/javascripts/discourse/app/components/d-modal-cancel.hbs b/app/assets/javascripts/discourse/app/components/d-modal-cancel.hbs index f66de85d829..f409a846791 100644 --- a/app/assets/javascripts/discourse/app/components/d-modal-cancel.hbs +++ b/app/assets/javascripts/discourse/app/components/d-modal-cancel.hbs @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/d-modal-cancel.js b/app/assets/javascripts/discourse/app/components/d-modal-cancel.js deleted file mode 100644 index 0e6d50b17d4..00000000000 --- a/app/assets/javascripts/discourse/app/components/d-modal-cancel.js +++ /dev/null @@ -1,4 +0,0 @@ -import Component from "@ember/component"; -export default Component.extend({ - tagName: "", -}); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js index 299e1038ad7..165303a677d 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js @@ -490,4 +490,20 @@ module("Integration | Component | select-kit/single-select", function (hooks) { assert.dom(".single-select.is-expanded").exists(); }); + + test("options.formName", async function (assert) { + setDefaultState(this); + await render(hbs` + + `); + + assert + .dom('input[name="foo"]') + .hasAttribute("type", "hidden") + .hasAttribute("value", "1"); + }); }); diff --git a/app/assets/javascripts/select-kit/addon/components/select-kit.js b/app/assets/javascripts/select-kit/addon/components/select-kit.js index fa2d49b1367..8a9ed97ee68 100644 --- a/app/assets/javascripts/select-kit/addon/components/select-kit.js +++ b/app/assets/javascripts/select-kit/addon/components/select-kit.js @@ -311,6 +311,7 @@ export default Component.extend( hiddenValues: null, disabled: false, expandedOnInsert: false, + formName: null, }, autoFilterable: computed("content.[]", "selectKit.filter", function () { diff --git a/app/assets/javascripts/select-kit/addon/components/selected-name.hbs b/app/assets/javascripts/select-kit/addon/components/selected-name.hbs index 1b823e8ba48..1273b32751e 100644 --- a/app/assets/javascripts/select-kit/addon/components/selected-name.hbs +++ b/app/assets/javascripts/select-kit/addon/components/selected-name.hbs @@ -6,6 +6,14 @@ data-name={{this.name}} class="select-kit-selected-name selected-name choice" > + {{#if this.selectKit.options.formName}} + + {{/if}} + {{#if this.item.icon}} {{d-icon this.item.icon}} {{/if}} diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-summary.hbs b/plugins/chat/assets/javascripts/discourse/components/channel-summary.hbs deleted file mode 100644 index eed8d85a0c9..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/channel-summary.hbs +++ /dev/null @@ -1,22 +0,0 @@ - - {{i18n "chat.summarization.description"}} - -
- - - {{#unless this.loading}} -

{{this.summary}}

- {{/unless}} -
- -
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/channel-summary.js b/plugins/chat/assets/javascripts/discourse/components/channel-summary.js deleted file mode 100644 index 881ded2750a..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/channel-summary.js +++ /dev/null @@ -1,65 +0,0 @@ -import Component from "@glimmer/component"; -import { tracked } from "@glimmer/tracking"; -import { ajax } from "discourse/lib/ajax"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { action } from "@ember/object"; -import I18n from "I18n"; - -export default class ChannelSumarry extends Component { - @tracked sinceHours = null; - @tracked loading = false; - @tracked availableSummaries = {}; - @tracked summary = null; - sinceOptions = [ - { - name: I18n.t("chat.summarization.since", { count: 1 }), - value: 1, - }, - { - name: I18n.t("chat.summarization.since", { count: 3 }), - value: 3, - }, - { - name: I18n.t("chat.summarization.since", { count: 6 }), - value: 6, - }, - { - name: I18n.t("chat.summarization.since", { count: 12 }), - value: 12, - }, - { - name: I18n.t("chat.summarization.since", { count: 24 }), - value: 24, - }, - { - name: I18n.t("chat.summarization.since", { count: 72 }), - value: 72, - }, - { - name: I18n.t("chat.summarization.since", { count: 168 }), - value: 168, - }, - ]; - - @action - summarize(value) { - this.loading = true; - - if (this.availableSummaries[value]) { - this.summary = this.availableSummaries[value]; - this.loading = false; - return; - } - - ajax(`/chat/api/channels/${this.args.channelId}/summarize`, { - method: "GET", - data: { since: value }, - }) - .then((data) => { - this.availableSummaries[this.sinceHours] = data.summary; - this.summary = this.availableSummaries[this.sinceHours]; - }) - .catch(popupAjaxError) - .finally(() => (this.loading = false)); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list.js b/plugins/chat/assets/javascripts/discourse/components/channels-list.js index d25d157e0aa..9f6e96e87c0 100644 --- a/plugins/chat/assets/javascripts/discourse/components/channels-list.js +++ b/plugins/chat/assets/javascripts/discourse/components/channels-list.js @@ -4,7 +4,7 @@ import { action } from "@ember/object"; import { schedule } from "@ember/runloop"; import { inject as service } from "@ember/service"; import { tracked } from "@glimmer/tracking"; -import ChatNewMessageModal from "discourse/plugins/chat/discourse/components/modal/chat-new-message"; +import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message"; export default class ChannelsList extends Component { @service chat; @@ -30,7 +30,7 @@ export default class ChannelsList extends Component { @action openNewMessageModal() { - this.modal.show(ChatNewMessageModal); + this.modal.show(ChatModalNewMessage); } get showMobileDirectMessageButton() { diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js b/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js index 2f3547b6146..70c584587a1 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-browse-view.js @@ -4,13 +4,15 @@ import { action, computed } from "@ember/object"; import { schedule } from "@ember/runloop"; import { inject as service } from "@ember/service"; import discourseDebounce from "discourse-common/lib/debounce"; -import showModal from "discourse/lib/show-modal"; -import ChatNewMessageModal from "discourse/plugins/chat/discourse/components/modal/chat-new-message"; +import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message"; +import ChatModalCreateChannel from "discourse/plugins/chat/discourse/components/chat/modal/create-channel"; const TABS = ["all", "open", "closed", "archived"]; export default class ChatBrowseView extends Component { @service chatApi; + @service modal; + tagName = ""; didReceiveAttrs() { @@ -41,7 +43,7 @@ export default class ChatBrowseView extends Component { @action showChatNewMessageModal() { - this.modal.show(ChatNewMessageModal); + this.modal.show(ChatModalNewMessage); } @action @@ -66,7 +68,7 @@ export default class ChatBrowseView extends Component { @action createChannel() { - showModal("create-channel"); + this.modal.show(ChatModalCreateChannel); } @action diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.hbs deleted file mode 100644 index d4da56380ae..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.hbs +++ /dev/null @@ -1,30 +0,0 @@ - -
-

{{this.instructionsText}}

- - -
-
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.js deleted file mode 100644 index 17d9420f1d1..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-archive-modal-inner.js +++ /dev/null @@ -1,108 +0,0 @@ -import Component from "@ember/component"; -import I18n from "I18n"; -import discourseLater from "discourse-common/lib/later"; -import { isEmpty } from "@ember/utils"; -import discourseComputed from "discourse-common/utils/decorators"; -import { action } from "@ember/object"; -import { equal } from "@ember/object/computed"; -import { inject as service } from "@ember/service"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { - EXISTING_TOPIC_SELECTION, - NEW_TOPIC_SELECTION, -} from "discourse/plugins/chat/discourse/components/chat-to-topic-selector"; -import { CHANNEL_STATUSES } from "discourse/plugins/chat/discourse/models/chat-channel"; -import { htmlSafe } from "@ember/template"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default Component.extend(ModalFunctionality, { - chat: service(), - chatApi: service(), - tagName: "", - chatChannel: null, - - selection: NEW_TOPIC_SELECTION, - newTopic: equal("selection", NEW_TOPIC_SELECTION), - existingTopic: equal("selection", EXISTING_TOPIC_SELECTION), - - saving: false, - - topicTitle: null, - categoryId: null, - tags: null, - selectedTopicId: null, - - @action - archiveChannel() { - this.set("saving", true); - - return this.chatApi - .createChannelArchive(this.chatChannel.id, this._data()) - .then(() => { - this.flash(I18n.t("chat.channel_archive.process_started"), "success"); - this.chatChannel.status = CHANNEL_STATUSES.archived; - - discourseLater(() => { - this.closeModal(); - }, 3000); - }) - .catch(popupAjaxError) - .finally(() => this.set("saving", false)); - }, - - _data() { - const data = { - type: this.selection, - }; - if (this.newTopic) { - data.title = this.topicTitle; - data.category_id = this.categoryId; - data.tags = this.tags; - } - if (this.existingTopic) { - data.topic_id = this.selectedTopicId; - } - return data; - }, - - @discourseComputed("saving", "selectedTopicId", "topicTitle", "selection") - buttonDisabled(saving, selectedTopicId, topicTitle) { - if (saving) { - return true; - } - if ( - this.newTopic && - (!topicTitle || - topicTitle.length < this.siteSettings.min_topic_title_length || - topicTitle.length > this.siteSettings.max_topic_title_length) - ) { - return true; - } - - if (this.existingTopic && isEmpty(selectedTopicId)) { - return true; - } - return false; - }, - - @discourseComputed() - instructionLabels() { - const labels = {}; - labels[NEW_TOPIC_SELECTION] = I18n.t( - "chat.selection.new_topic.instructions_channel_archive" - ); - labels[EXISTING_TOPIC_SELECTION] = I18n.t( - "chat.selection.existing_topic.instructions_channel_archive" - ); - return labels; - }, - - @discourseComputed() - instructionsText() { - return htmlSafe( - I18n.t("chat.channel_archive.instructions", { - channelTitle: this.chatChannel.escapedTitle, - }) - ); - }, -}); diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.hbs deleted file mode 100644 index faf2829c557..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.hbs +++ /dev/null @@ -1,30 +0,0 @@ - -
-

- {{this.instructionsText}} -

-
- - -
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.js deleted file mode 100644 index 9a34dd80e53..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-delete-modal-inner.js +++ /dev/null @@ -1,65 +0,0 @@ -import Component from "@ember/component"; -import { isEmpty } from "@ember/utils"; -import I18n from "I18n"; -import discourseComputed from "discourse-common/utils/decorators"; -import { action } from "@ember/object"; -import { inject as service } from "@ember/service"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import discourseLater from "discourse-common/lib/later"; -import { htmlSafe } from "@ember/template"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default Component.extend(ModalFunctionality, { - chat: service(), - chatApi: service(), - router: service(), - tagName: "", - chatChannel: null, - channelNameConfirmation: null, - deleting: false, - confirmed: false, - - @discourseComputed("deleting", "channelNameConfirmation", "confirmed") - buttonDisabled(deleting, channelNameConfirmation, confirmed) { - if (deleting || confirmed) { - return true; - } - - if ( - isEmpty(channelNameConfirmation) || - channelNameConfirmation.toLowerCase() !== - this.chatChannel.title.toLowerCase() - ) { - return true; - } - return false; - }, - - @action - deleteChannel() { - this.set("deleting", true); - - return this.chatApi - .destroyChannel(this.chatChannel.id, this.channelNameConfirmation) - .then(() => { - this.set("confirmed", true); - this.flash(I18n.t("chat.channel_delete.process_started"), "success"); - - discourseLater(() => { - this.closeModal(); - this.router.transitionTo("chat"); - }, 3000); - }) - .catch(popupAjaxError) - .finally(() => this.set("deleting", false)); - }, - - @discourseComputed() - instructionsText() { - return htmlSafe( - I18n.t("chat.channel_delete.instructions", { - name: this.chatChannel.escapedTitle, - }) - ); - }, -}); diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js index 2c1398bc0f1..dc5560886ef 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-settings-view.js @@ -1,8 +1,10 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; import { inject as service } from "@ember/service"; -import showModal from "discourse/lib/show-modal"; import I18n from "I18n"; +import ChatModalArchiveChannel from "discourse/plugins/chat/discourse/components/chat/modal/archive-channel"; +import ChatModalDeleteChannel from "discourse/plugins/chat/discourse/components/chat/modal/delete-channel"; +import ChatModalToggleChannelStatus from "discourse/plugins/chat/discourse/components/chat/modal/toggle-channel-status"; const NOTIFICATION_LEVELS = [ { name: I18n.t("chat.notification_levels.never"), value: "never" }, @@ -41,6 +43,7 @@ export default class ChatChannelSettingsView extends Component { @service siteSettings; @service router; @service dialog; + @service modal; notificationLevels = NOTIFICATION_LEVELS; mutedOptions = MUTED_OPTIONS; @@ -107,20 +110,21 @@ export default class ChatChannelSettingsView extends Component { @action onArchiveChannel() { - const controller = showModal("chat-channel-archive-modal"); - controller.set("chatChannel", this.args.channel); + return this.modal.show(ChatModalArchiveChannel, { + model: { channel: this.args.channel }, + }); } @action onDeleteChannel() { - const controller = showModal("chat-channel-delete-modal"); - controller.set("chatChannel", this.args.channel); + return this.modal.show(ChatModalDeleteChannel, { + model: { channel: this.args.channel }, + }); } @action onToggleChannelState() { - const controller = showModal("chat-channel-toggle"); - controller.set("chatChannel", this.args.channel); + this.modal.show(ChatModalToggleChannelStatus, { model: this.args.channel }); } @action diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.hbs deleted file mode 100644 index 237017a1864..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.hbs +++ /dev/null @@ -1,14 +0,0 @@ - -
-

{{this.instructions}}

-
-
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js index e5a1740ca5b..304cd235719 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js @@ -25,6 +25,7 @@ import { initUserStatusHtml, renderUserStatusHtml, } from "discourse/lib/user-status-on-autocomplete"; +import ChatModalChannelSummary from "discourse/plugins/chat/discourse/components/chat/modal/channel-summary"; export default class ChatComposer extends Component { @service capabilities; @@ -39,6 +40,7 @@ export default class ChatComposer extends Component { @service currentUser; @service chatApi; @service chatDraftsManager; + @service modal; @tracked isFocused = false; @tracked inProgressUploadsCount = 0; @@ -377,8 +379,8 @@ export default class ChatComposer extends Component { @action showChannelSummaryModal() { - showModal("channel-summary").setProperties({ - channelId: this.args.channel.id, + this.modal.show(ChatModalChannelSummary, { + model: { channelId: this.args.channel.id }, }); } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.hbs deleted file mode 100644 index c89b7fe5c36..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.hbs +++ /dev/null @@ -1,28 +0,0 @@ - -
-

{{this.instructionsText}}

-
- - -
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-separator-date.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message-separator-date.hbs index 2249396840e..9b5361dcd2c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-separator-date.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-separator-date.hbs @@ -5,11 +5,7 @@ (if @message.newest "with-last-visit") }} role="button" - {{on - "click" - (fn @fetchMessagesByDate @message.firstMessageOfTheDayAt) - passive=true - }} + {{on "click" this.onDateClick passive=true}} >
+ <:body> +

+ {{this.instructionsText}} +

+ + + <:footer> + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/archive-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/archive-channel.js new file mode 100644 index 00000000000..f8f5b11b4e6 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/archive-channel.js @@ -0,0 +1,112 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import { tracked } from "@glimmer/tracking"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { htmlSafe } from "@ember/template"; +import I18n from "I18n"; +import discourseLater from "discourse-common/lib/later"; +import { + EXISTING_TOPIC_SELECTION, + NEW_TOPIC_SELECTION, +} from "discourse/plugins/chat/discourse/components/chat-to-topic-selector"; +import { CHANNEL_STATUSES } from "discourse/plugins/chat/discourse/models/chat-channel"; +import { isEmpty } from "@ember/utils"; + +export default class ChatModalArchiveChannel extends Component { + @service chatApi; + @service siteSettings; + + @tracked selection = NEW_TOPIC_SELECTION; + @tracked saving = false; + @tracked topicTitle = null; + @tracked categoryId = null; + @tracked tags = null; + @tracked selectedTopicId = null; + @tracked flash; + @tracked flashType; + + get channel() { + return this.args.model.channel; + } + + get newTopic() { + return this.selection === NEW_TOPIC_SELECTION; + } + + get existingTopic() { + return this.selection === EXISTING_TOPIC_SELECTION; + } + + get buttonDisabled() { + if (this.saving) { + return true; + } + + if ( + this.newTopic && + (!this.topicTitle || + this.topicTitle.length < this.siteSettings.min_topic_title_length || + this.topicTitle.length > this.siteSettings.max_topic_title_length) + ) { + return true; + } + + if (this.existingTopic && isEmpty(this.selectedTopicId)) { + return true; + } + + return false; + } + + get instructionLabels() { + const labels = {}; + labels[NEW_TOPIC_SELECTION] = I18n.t( + "chat.selection.new_topic.instructions_channel_archive" + ); + labels[EXISTING_TOPIC_SELECTION] = I18n.t( + "chat.selection.existing_topic.instructions_channel_archive" + ); + return labels; + } + + get instructionsText() { + return htmlSafe( + I18n.t("chat.channel_archive.instructions", { + channelTitle: this.channel.escapedTitle, + }) + ); + } + + @action + archiveChannel() { + this.saving = true; + + return this.chatApi + .createChannelArchive(this.channel.id, this.#data()) + .then(() => { + this.flash = I18n.t("chat.channel_archive.process_started"); + this.flashType = "success"; + this.channel.status = CHANNEL_STATUSES.archived; + + discourseLater(() => { + this.args.closeModal(); + }, 3000); + }) + .catch(popupAjaxError) + .finally(() => (this.saving = false)); + } + + #data() { + const data = { type: this.selection }; + if (this.newTopic) { + data.title = this.topicTitle; + data.category_id = this.categoryId; + data.tags = this.tags; + } + if (this.existingTopic) { + data.topic_id = this.selectedTopicId; + } + return data; + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.hbs new file mode 100644 index 00000000000..0e16015ae21 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.hbs @@ -0,0 +1,22 @@ + + <:body> + {{i18n "chat.summarization.description"}} + + +

{{this.summary}}

+
+ + <:footer> + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.js new file mode 100644 index 00000000000..199118729d4 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/channel-summary.js @@ -0,0 +1,47 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { action } from "@ember/object"; +import I18n from "I18n"; +import { inject as service } from "@ember/service"; + +export default class ChatModalChannelSummary extends Component { + @service chatApi; + + @tracked sinceHours = null; + @tracked loading = false; + @tracked summary = null; + + availableSummaries = {}; + + sinceOptions = [1, 3, 6, 12, 24, 72, 168].map((hours) => { + return { + name: I18n.t("chat.summarization.since", { count: hours }), + value: hours, + }; + }); + + get channelId() { + return this.args.model.channelId; + } + + @action + summarize(since) { + this.loading = true; + + if (this.availableSummaries[since]) { + this.summary = this.availableSummaries[since]; + this.loading = false; + return; + } + + return this.chatApi + .summarize(this.channelId, { since }) + .then((data) => { + this.availableSummaries[this.sinceHours] = data.summary; + this.summary = this.availableSummaries[this.sinceHours]; + }) + .catch(popupAjaxError) + .finally(() => (this.loading = false)); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs new file mode 100644 index 00000000000..06e8213a245 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.hbs @@ -0,0 +1,136 @@ + + <:body> +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + + {{#if this.categoryPermissionsHint}} +
+ {{this.categoryPermissionsHint}} +
+ {{/if}} +
+ + {{#if this.autoJoinAvailable}} +
+ +
+ {{/if}} + + {{#if this.threadingAvailable}} +
+ +
+ {{/if}} + + <:footer> + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/controllers/create-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.js similarity index 62% rename from plugins/chat/assets/javascripts/discourse/controllers/create-channel.js rename to plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.js index d4e464a0105..7d5a35c0f46 100644 --- a/plugins/chat/assets/javascripts/discourse/controllers/create-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/create-channel.js @@ -2,14 +2,13 @@ import { escapeExpression } from "discourse/lib/utilities"; import { ajax } from "discourse/lib/ajax"; import { cancel } from "@ember/runloop"; import discourseDebounce from "discourse-common/lib/debounce"; -import Controller from "@ember/controller"; +import Component from "@glimmer/component"; import I18n from "I18n"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { action, computed } from "@ember/object"; -import { gt, notEmpty } from "@ember/object/computed"; +import { action } from "@ember/object"; import { inject as service } from "@ember/service"; import { isBlank, isPresent } from "@ember/utils"; import { htmlSafe } from "@ember/template"; +import { tracked } from "@glimmer/tracking"; const DEFAULT_HINT = htmlSafe( I18n.t("chat.create_channel.choose_category.default_hint", { @@ -18,9 +17,7 @@ const DEFAULT_HINT = htmlSafe( }) ); -export default class CreateChannelController extends Controller.extend( - ModalFunctionality -) { +export default class ChatModalCreateChannel extends Component { @service chat; @service dialog; @service chatChannelsManager; @@ -28,21 +25,30 @@ export default class CreateChannelController extends Controller.extend( @service router; @service currentUser; @service siteSettings; + @service site; - category = null; - categoryId = null; - name = ""; - slug = ""; - autoGeneratedSlug = ""; - description = ""; - categoryPermissionsHint = null; - autoJoinUsers = false; - autoJoinWarning = ""; - loadingPermissionHint = false; - threadingEnabled = false; + @tracked flash; + @tracked name; + @tracked category; + @tracked categoryId; + @tracked autoGeneratedSlug = ""; + @tracked categoryPermissionsHint; + @tracked autoJoinWarning = ""; + @tracked loadingPermissionHint = false; - @notEmpty("category") categorySelected; - @gt("siteSettings.max_chat_auto_joined_users", 0) autoJoinAvailable; + #generateSlugHandler = null; + + willDestroy() { + cancel(this.#generateSlugHandler); + } + + get autoJoinAvailable() { + return this.siteSettings.max_chat_auto_joined_users > 0; + } + + get categorySelected() { + return isPresent(this.category); + } get threadingAvailable() { return ( @@ -51,69 +57,88 @@ export default class CreateChannelController extends Controller.extend( ); } - @computed("categorySelected", "name") get createDisabled() { return !this.categorySelected || isBlank(this.name); } - @computed("categorySelected", "name") get categoryName() { return this.categorySelected && isPresent(this.name) ? escapeExpression(this.name) : null; } + @action onShow() { - this.set("categoryPermissionsHint", DEFAULT_HINT); + this.categoryPermissionsHint = DEFAULT_HINT; } - onClose() { - cancel(this.generateSlugHandler); - this.setProperties({ - categoryId: null, - category: null, - name: "", - description: "", - slug: "", - autoGeneratedSlug: "", - categoryPermissionsHint: DEFAULT_HINT, - autoJoinWarning: "", - }); + @action + onCategoryChange(categoryId) { + const category = categoryId + ? this.site.categories.findBy("id", categoryId) + : null; + this.#updatePermissionsHint(category); + + const name = this.name || category?.name || ""; + this.categoryId = categoryId; + this.category = category; + this.name = name; + this.#debouncedGenerateSlug(name); } - _createChannel() { - const data = { - chatable_id: this.categoryId, - name: this.name, - slug: this.slug || this.autoGeneratedSlug, - description: this.description, - auto_join_users: this.autoJoinUsers, - threading_enabled: this.threadingEnabled, - }; + @action + onNameChange(name) { + this.#debouncedGenerateSlug(name); + } + @action + onSave(event) { + event.preventDefault(); + + if (this.createDisabled) { + return; + } + + const formData = new FormData(event.currentTarget); + const data = Object.fromEntries(formData.entries()); + data.auto_join_users = data.auto_join_users === "on"; + data.slug ??= this.autoGeneratedSlug; + data.threading_enabled = data.threading_enabled === "on"; + + if (data.auto_join_users) { + this.dialog.yesNoConfirm({ + message: this.autoJoinWarning, + didConfirm: () => this.#createChannel(data), + }); + } else { + this.#createChannel(data); + } + } + + #createChannel(data) { return this.chatApi .createChannel(data) .then((channel) => { - this.send("closeModal"); + this.args.closeModal(); this.chatChannelsManager.follow(channel); this.router.transitionTo("chat.channel", ...channel.routeModels); }) .catch((e) => { - this.flash(e.jqXHR.responseJSON.errors[0], "error"); + this.flash = e.jqXHR.responseJSON.errors[0]; }); } - _buildCategorySlug(category) { + #buildCategorySlug(category) { const parent = category.parentCategory; if (parent) { - return `${this._buildCategorySlug(parent)}/${category.slug}`; + return `${this.#buildCategorySlug(parent)}/${category.slug}`; } else { return category.slug; } } - _updateAutoJoinConfirmWarning(category, catPermissions) { + #updateAutoJoinConfirmWarning(category, catPermissions) { const allowedGroups = catPermissions.allowed_groups; let warning; @@ -158,19 +183,19 @@ export default class CreateChannelController extends Controller.extend( ); } - this.set("autoJoinWarning", warning); + this.autoJoinWarning = warning; } - _updatePermissionsHint(category) { + #updatePermissionsHint(category) { if (category) { - const fullSlug = this._buildCategorySlug(category); + const fullSlug = this.#buildCategorySlug(category); - this.set("loadingPermissionHint", true); + this.loadingPermissionHint = true; return this.chatApi .categoryPermissions(category.id) .then((catPermissions) => { - this._updateAutoJoinConfirmWarning(category, catPermissions); + this.#updateAutoJoinConfirmWarning(category, catPermissions); const allowedGroups = catPermissions.allowed_groups; const settingLink = `/c/${escapeExpression(fullSlug)}/edit/security`; let hint; @@ -207,77 +232,40 @@ export default class CreateChannelController extends Controller.extend( break; } - this.set("categoryPermissionsHint", htmlSafe(hint)); + this.categoryPermissionsHint = htmlSafe(hint); }) .finally(() => { - this.set("loadingPermissionHint", false); + this.loadingPermissionHint = false; }); } else { - this.set("categoryPermissionsHint", DEFAULT_HINT); - this.set("autoJoinWarning", ""); + this.categoryPermissionsHint = DEFAULT_HINT; + this.autoJoinWarning = ""; } } // intentionally not showing AJAX error for this, we will autogenerate // the slug server-side if they leave it blank - _generateSlug(name) { - ajax("/slugs.json", { type: "POST", data: { name } }).then((response) => { - this.set("autoGeneratedSlug", response.slug); - }); + #generateSlug(name) { + return ajax("/slugs.json", { type: "POST", data: { name } }).then( + (response) => { + this.autoGeneratedSlug = response.slug; + } + ); } - _debouncedGenerateSlug(name) { - cancel(this.generateSlugHandler); - this._clearAutoGeneratedSlug(); + #debouncedGenerateSlug(name) { + cancel(this.#generateSlugHandler); + this.autoGeneratedSlug = ""; + if (!name) { return; } - this.generateSlugHandler = discourseDebounce( + + this.#generateSlugHandler = discourseDebounce( this, - this._generateSlug, + this.#generateSlug, name, 300 ); } - - _clearAutoGeneratedSlug() { - this.set("autoGeneratedSlug", ""); - } - - @action - onCategoryChange(categoryId) { - let category = categoryId - ? this.site.categories.findBy("id", categoryId) - : null; - this._updatePermissionsHint(category); - - const name = this.name || category?.name || ""; - this.setProperties({ - categoryId, - category, - name, - }); - this._debouncedGenerateSlug(name); - } - - @action - onNameChange(name) { - this._debouncedGenerateSlug(name); - } - - @action - create() { - if (this.createDisabled) { - return; - } - - if (this.autoJoinUsers) { - this.dialog.yesNoConfirm({ - message: this.autoJoinWarning, - didConfirm: () => this._createChannel(), - }); - } else { - this._createChannel(); - } - } } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.hbs new file mode 100644 index 00000000000..3e7c026a977 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.hbs @@ -0,0 +1,32 @@ + + <:body> +

+ {{this.instructionsText}} +

+ + + + <:footer> + + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.js new file mode 100644 index 00000000000..affb248edc6 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/delete-channel.js @@ -0,0 +1,68 @@ +import Component from "@glimmer/component"; +import { isEmpty } from "@ember/utils"; +import I18n from "I18n"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import discourseLater from "discourse-common/lib/later"; +import { htmlSafe } from "@ember/template"; +import { tracked } from "@glimmer/tracking"; + +export default class ChatModalDeleteChannel extends Component { + @service chatApi; + @service router; + + @tracked channelNameConfirmation; + @tracked deleting = false; + @tracked confirmed = false; + @tracked flash; + @tracked flashType; + + get channel() { + return this.args.model.channel; + } + + get buttonDisabled() { + if (this.deleting || this.confirmed) { + return true; + } + + if ( + isEmpty(this.channelNameConfirmation) || + this.channelNameConfirmation.toLowerCase() !== + this.channel.title.toLowerCase() + ) { + return true; + } + + return false; + } + + get instructionsText() { + return htmlSafe( + I18n.t("chat.channel_delete.instructions", { + name: this.channel.escapedTitle, + }) + ); + } + + @action + deleteChannel() { + this.deleting = true; + + return this.chatApi + .destroyChannel(this.channel.id, this.channelNameConfirmation) + .then(() => { + this.confirmed = true; + this.flash = I18n.t("chat.channel_delete.process_started"); + this.flashType = "success"; + + discourseLater(() => { + this.args.closeModal(); + this.router.transitionTo("chat"); + }, 3000); + }) + .catch(popupAjaxError) + .finally(() => (this.deleting = false)); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs new file mode 100644 index 00000000000..3a21233edbd --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.hbs @@ -0,0 +1,37 @@ + + <:body> + {{i18n + "chat.channel_edit_description_modal.description" + }} + + + + + <:footer> + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.js new file mode 100644 index 00000000000..2336c6cc040 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-description.js @@ -0,0 +1,49 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { tracked } from "@glimmer/tracking"; +import { inject as service } from "@ember/service"; + +const DESCRIPTION_MAX_LENGTH = 280; + +export default class ChatModalEditChannelDescription extends Component { + @service chatApi; + + @tracked editedDescription = this.channel.description || ""; + @tracked flash; + + get channel() { + return this.args.model; + } + + get isSaveDisabled() { + return ( + this.channel.description === this.editedDescription || + this.editedDescription?.length > DESCRIPTION_MAX_LENGTH + ); + } + + get descriptionMaxLength() { + return DESCRIPTION_MAX_LENGTH; + } + + @action + onSaveChatChannelDescription() { + return this.chatApi + .updateChannel(this.channel.id, { description: this.editedDescription }) + .then((result) => { + this.channel.description = result.channel.description; + this.args.closeModal(); + }) + .catch((event) => { + if (event.jqXHR?.responseJSON?.errors) { + this.flash = event.jqXHR.responseJSON.errors.join("\n"); + } + }); + } + + @action + onChangeChatChannelDescription(description) { + this.flash = null; + this.editedDescription = description; + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.hbs new file mode 100644 index 00000000000..b4d8ee1df1c --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.hbs @@ -0,0 +1,54 @@ + + <:body> +
+ + +
+ +
+ + +
+ + <:footer> + + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.js new file mode 100644 index 00000000000..433d6ac0ea6 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/edit-channel-name.js @@ -0,0 +1,84 @@ +import Component from "@glimmer/component"; +import discourseDebounce from "discourse-common/lib/debounce"; +import { ajax } from "discourse/lib/ajax"; +import { cancel } from "@ember/runloop"; +import { action } from "@ember/object"; +import { extractError } from "discourse/lib/ajax-error"; +import { tracked } from "@glimmer/tracking"; +import { inject as service } from "@ember/service"; + +export default class ChatModalEditChannelName extends Component { + @service chatApi; + @service siteSettings; + + @tracked editedName = this.channel.title; + @tracked editedSlug = this.channel.slug; + @tracked autoGeneratedSlug = ""; + @tracked flash; + + #generateSlugHandler = null; + + get channel() { + return this.args.model; + } + + get isSaveDisabled() { + return ( + (this.channel.title === this.editedName && + this.channel.slug === this.editedSlug) || + this.editedName?.length > this.siteSettings.max_topic_title_length + ); + } + + @action + onSave() { + return this.chatApi + .updateChannel(this.channel.id, { + name: this.editedName, + slug: this.editedSlug || this.autoGeneratedSlug || this.channel.slug, + }) + .then((result) => { + this.channel.title = result.channel.title; + this.args.closeModal(); + }) + .catch((error) => (this.flash = extractError(error))); + } + + @action + onChangeChatChannelName(title) { + this.flash = null; + this.#debouncedGenerateSlug(title); + } + + @action + onChangeChatChannelSlug() { + this.flash = null; + this.#debouncedGenerateSlug(this.editedName); + } + + #debouncedGenerateSlug(name) { + cancel(this.#generateSlugHandler); + this.autoGeneratedSlug = ""; + + if (!name) { + return; + } + + this.#generateSlugHandler = discourseDebounce( + this, + this.#generateSlug, + name, + 300 + ); + } + + // intentionally not showing AJAX error for this, we will autogenerate + // the slug server-side if they leave it blank + #generateSlug(name) { + return ajax("/slugs.json", { type: "POST", data: { name } }).then( + (response) => { + this.autoGeneratedSlug = response.slug; + } + ); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.hbs new file mode 100644 index 00000000000..2d09a13ba89 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.hbs @@ -0,0 +1,29 @@ + + <:body> + {{#if this.selectedMessageCount}} +

{{this.instructionsText}}

+ {{/if}} + + + + <:footer> + + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.js similarity index 64% rename from plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.js rename to plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.js index 86a2dd8c4c1..ca4ff3afbd4 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-message-move-to-channel-modal-inner.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/move-message-to-channel.js @@ -1,35 +1,49 @@ -import Component from "@ember/component"; -import I18n from "I18n"; -import { reads } from "@ember/object/computed"; +import Component from "@glimmer/component"; import { isBlank } from "@ember/utils"; -import { action, computed } from "@ember/object"; +import { action } from "@ember/object"; import { inject as service } from "@ember/service"; +import { tracked } from "@glimmer/tracking"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { htmlSafe } from "@ember/template"; +import I18n from "I18n"; -export default class MoveToChannelModalInner extends Component { +export default class ChatModalMoveMessageToChannel extends Component { @service chat; @service chatApi; @service router; @service chatChannelsManager; - tagName = ""; - sourceChannel = null; - destinationChannelId = null; - selectedMessageIds = null; + @tracked destinationChannelId; - @reads("selectedMessageIds.length") selectedMessageCount; + get sourceChannel() { + return this.args.model.sourceChannel; + } + + get selectedMessageIds() { + return this.args.model.selectedMessageIds; + } + + get selectedMessageCount() { + return this.selectedMessageIds?.length; + } - @computed("destinationChannelId") get disableMoveButton() { return isBlank(this.destinationChannelId); } - @computed("chatChannelsManager.publicMessageChannels.[]") get availableChannels() { - return this.chatChannelsManager.publicMessageChannels.rejectBy( - "id", - this.sourceChannel.id + return ( + this.args.model.availableChannels || + this.chatChannelsManager.publicMessageChannels + ).rejectBy("id", this.sourceChannel.id); + } + + get instructionsText() { + return htmlSafe( + I18n.t("chat.move_to_channel.instructions", { + channelTitle: this.sourceChannel.escapedTitle, + count: this.selectedMessageCount, + }) ); } @@ -50,14 +64,4 @@ export default class MoveToChannelModalInner extends Component { }) .catch(popupAjaxError); } - - @computed() - get instructionsText() { - return htmlSafe( - I18n.t("chat.move_to_channel.instructions", { - channelTitle: this.sourceChannel.escapedTitle, - count: this.selectedMessageCount, - }) - ); - } } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs new file mode 100644 index 00000000000..05b535f5e6c --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.hbs @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.hbs new file mode 100644 index 00000000000..348bf2ccd77 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.hbs @@ -0,0 +1,26 @@ + + <:body> + + + + <:footer> + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.js similarity index 69% rename from plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.js rename to plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.js index 18af082ba10..6871c195444 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.js @@ -4,25 +4,30 @@ import { tracked } from "@glimmer/tracking"; import { inject as service } from "@ember/service"; import { action } from "@ember/object"; -export default class ChatThreadSettingsModalInner extends Component { +export default class ChatModalThreadSettings extends Component { @service chatApi; - @tracked editedTitle = this.args.thread.title || ""; + @tracked editedTitle = this.thread.title || ""; @tracked saving = false; get buttonDisabled() { return this.saving; } + get thread() { + return this.args.model; + } + @action saveThread() { this.saving = true; + this.chatApi - .editThread(this.args.thread.channel.id, this.args.thread.id, { + .editThread(this.thread.channel.id, this.thread.id, { title: this.editedTitle, }) .then(() => { - this.args.thread.title = this.editedTitle; + this.thread.title = this.editedTitle; this.args.closeModal(); }) .catch(popupAjaxError) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.hbs new file mode 100644 index 00000000000..85e35103ef5 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.hbs @@ -0,0 +1,20 @@ + + <:body> +

{{this.instructions}}

+ + <:footer> + + +
\ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.js b/plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.js similarity index 65% rename from plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.js rename to plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.js index 5ed0b2dbdf5..d801aa67fe5 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-toggle-view.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/toggle-channel-status.js @@ -1,40 +1,37 @@ -import Component from "@ember/component"; +import Component from "@glimmer/component"; +import { action } from "@ember/object"; import { htmlSafe } from "@ember/template"; import { CHANNEL_STATUSES } from "discourse/plugins/chat/discourse/models/chat-channel"; import I18n from "I18n"; -import { action, computed } from "@ember/object"; import { inject as service } from "@ember/service"; import { popupAjaxError } from "discourse/lib/ajax-error"; -export default class ChatChannelToggleView extends Component { - @service chat; +export default class ChatModalToggleChannelStatus extends Component { @service chatApi; @service router; - tagName = ""; - channel = null; - onStatusChange = null; - @computed("channel.isClosed") + get channel() { + return this.args.model; + } + get buttonLabel() { - if (this.channel.isClosed) { + if (this.channel?.isClosed) { return "chat.channel_settings.open_channel"; } else { return "chat.channel_settings.close_channel"; } } - @computed("channel.isClosed") get instructions() { - if (this.channel.isClosed) { + if (this.channel?.isClosed) { return htmlSafe(I18n.t("chat.channel_open.instructions")); } else { return htmlSafe(I18n.t("chat.channel_close.instructions")); } } - @computed("channel.isClosed") get modalTitle() { - if (this.channel.isClosed) { + if (this.channel?.isClosed) { return "chat.channel_open.title"; } else { return "chat.channel_close.title"; @@ -42,15 +39,16 @@ export default class ChatChannelToggleView extends Component { } @action - changeChannelStatus() { + onStatusChange() { const status = this.channel.isClosed ? CHANNEL_STATUSES.open : CHANNEL_STATUSES.closed; return this.chatApi .updateChannelStatus(this.channel.id, status) - .finally(() => { - this.onStatusChange?.(this.channel); + .then(() => { + this.args.closeModal(); + this.router.transitionTo("chat.channel", ...this.channel.routeModels); }) .catch(popupAjaxError); } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/selection-manager.js b/plugins/chat/assets/javascripts/discourse/components/chat/selection-manager.js index 2c4a2e93428..9614e7b6d13 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/selection-manager.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/selection-manager.js @@ -1,6 +1,5 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; -import showModal from "discourse/lib/show-modal"; import { clipboardCopyAsync } from "discourse/lib/utilities"; import { getOwner } from "discourse-common/lib/get-owner"; import { isTesting } from "discourse-common/config/environment"; @@ -8,10 +7,12 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; import { inject as service } from "@ember/service"; import { bind } from "discourse-common/utils/decorators"; import { tracked } from "@glimmer/tracking"; +import ChatModalMoveMessageToChannel from "discourse/plugins/chat/discourse/components/chat/modal/move-message-to-channel"; export default class ChatSelectionManager extends Component { @service("composer") topicComposer; @service router; + @service modal; @service site; @service("chat-api") api; @@ -42,9 +43,11 @@ export default class ChatSelectionManager extends Component { @action openMoveMessageModal() { - showModal("chat-message-move-to-channel-modal").setProperties({ - sourceChannel: this.args.pane.channel, - selectedMessageIds: this.args.pane.selectedMessageIds, + this.modal.show(ChatModalMoveMessageToChannel, { + model: { + sourceChannel: this.args.pane.channel, + selectedMessageIds: this.args.pane.selectedMessageIds, + }, }); } diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread-list.js b/plugins/chat/assets/javascripts/discourse/components/chat/thread-list.js index b2e5f877b3f..bbc0b8c84f8 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread-list.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread-list.js @@ -124,6 +124,7 @@ export default class ChatThreadList extends Component { } #unsubscribe() { + // TODO (joffrey) In drawer we won't have channel anymore at this point this.messageBus.unsubscribe( `/chat/${this.args.channel.id}`, this.onMessageBus diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.js b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.js index 3ddce5f9eb0..4b863f04094 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat/thread/header.js @@ -1,11 +1,11 @@ import Component from "@glimmer/component"; import { NotificationLevels } from "discourse/lib/notification-levels"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import showModal from "discourse/lib/show-modal"; import { inject as service } from "@ember/service"; import { action } from "@ember/object"; import UserChatThreadMembership from "discourse/plugins/chat/discourse/models/user-chat-thread-membership"; import { tracked } from "@glimmer/tracking"; +import ChatModalThreadSettings from "discourse/plugins/chat/discourse/components/chat/modal/thread-settings"; export default class ChatThreadHeader extends Component { @service currentUser; @@ -14,6 +14,7 @@ export default class ChatThreadHeader extends Component { @service chatStateManager; @service chatHistory; @service site; + @service modal; @tracked persistedNotificationLevel = true; @@ -60,8 +61,7 @@ export default class ChatThreadHeader extends Component { @action openThreadSettings() { - const controller = showModal("chat-thread-settings-modal"); - controller.set("thread", this.args.thread); + this.modal.show(ChatModalThreadSettings, { model: this.args.thread }); } @action diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.hbs b/plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.hbs deleted file mode 100644 index 15b4ae124bb..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/chat/thread/settings-modal-inner.hbs +++ /dev/null @@ -1,22 +0,0 @@ - -
- - -
-
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.hbs b/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.hbs deleted file mode 100644 index d090f4c9fbf..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.hbs +++ /dev/null @@ -1,7 +0,0 @@ - - - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.js b/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.js deleted file mode 100644 index 3a4a62b1fbb..00000000000 --- a/plugins/chat/assets/javascripts/discourse/components/modal/chat-new-message.js +++ /dev/null @@ -1,6 +0,0 @@ -import Component from "@ember/component"; -import { inject as service } from "@ember/service"; - -export default class ChatNewMessageModal extends Component { - @service chat; -} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.hbs new file mode 100644 index 00000000000..d2409d2f27c --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js new file mode 100644 index 00000000000..57bcb49834a --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js @@ -0,0 +1,20 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import ChatModalArchiveChannel from "discourse/plugins/chat/discourse/components/chat/modal/archive-channel"; +import Component from "@glimmer/component"; + +export default class ChatStyleguideChatModalArchiveChannel extends Component { + @service modal; + + channel = fabricators.channel(); + + @action + openModal() { + return this.modal.show(ChatModalArchiveChannel, { + model: { + channel: this.channel, + }, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.hbs new file mode 100644 index 00000000000..099820a0a0f --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js new file mode 100644 index 00000000000..79008022af7 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js @@ -0,0 +1,16 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import Component from "@glimmer/component"; +import ChatModalChannelSummary from "discourse/plugins/chat/discourse/components/chat/modal/channel-summary"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; + +export default class ChatStyleguideChatModalChannelSummary extends Component { + @service modal; + + @action + openModal() { + return this.modal.show(ChatModalChannelSummary, { + model: { channelId: fabricators.channel().id }, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.hbs new file mode 100644 index 00000000000..e2747d289e6 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.js new file mode 100644 index 00000000000..3d37663d555 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-create-channel.js @@ -0,0 +1,13 @@ +import Component from "@glimmer/component"; +import ChatModalCreateChannel from "discourse/plugins/chat/discourse/components/chat/modal/create-channel"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; + +export default class ChatStyleguideChatModalCreateChannel extends Component { + @service modal; + + @action + openModal() { + return this.modal.show(ChatModalCreateChannel); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.hbs new file mode 100644 index 00000000000..f9787048ce6 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js new file mode 100644 index 00000000000..02bba90987b --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js @@ -0,0 +1,18 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import ChatModalDeleteChannel from "discourse/plugins/chat/discourse/components/chat/modal/delete-channel"; +import Component from "@glimmer/component"; + +export default class ChatStyleguideChatModalDeleteChannel extends Component { + @service modal; + + channel = fabricators.channel(); + + @action + openModal() { + return this.modal.show(ChatModalDeleteChannel, { + model: { channel: this.channel }, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.hbs new file mode 100644 index 00000000000..b7d5dcc2804 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js new file mode 100644 index 00000000000..018108bc2c7 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js @@ -0,0 +1,18 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import ChatModalEditChannelDescription from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-description"; +import Component from "@glimmer/component"; + +export default class ChatStyleguideChatModalEditChannelDescription extends Component { + @service modal; + + channel = fabricators.channel(); + + @action + openModal() { + return this.modal.show(ChatModalEditChannelDescription, { + model: this.channel, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.hbs new file mode 100644 index 00000000000..5a40bff03cd --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js new file mode 100644 index 00000000000..7e9770840ba --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js @@ -0,0 +1,18 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import ChatModalEditChannelName from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-name"; +import Component from "@glimmer/component"; + +export default class ChatStyleguideChatModalEditChannelName extends Component { + @service modal; + + channel = fabricators.channel(); + + @action + openModal() { + return this.modal.show(ChatModalEditChannelName, { + model: this.channel, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.hbs new file mode 100644 index 00000000000..e508bd7810a --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js new file mode 100644 index 00000000000..513dda5dcfe --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js @@ -0,0 +1,26 @@ +import Component from "@glimmer/component"; +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; +import ChatModalMoveMessageToChannel from "discourse/plugins/chat/discourse/components/chat/modal/move-message-to-channel"; + +export default class ChatStyleguideChatModalMoveMessageToChannel extends Component { + @service modal; + + channel = fabricators.channel(); + selectedMessageIds = [fabricators.message({ channel: this.channel })].mapBy( + "id" + ); + + @action + openModal() { + return this.modal.show(ChatModalMoveMessageToChannel, { + model: { + sourceChannel: this.channel, + selectedMessageIds: [ + fabricators.message({ channel: this.channel }), + ].mapBy("id"), + }, + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.hbs new file mode 100644 index 00000000000..e39c631ef7c --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.js new file mode 100644 index 00000000000..1ace191332a --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-new-message.js @@ -0,0 +1,13 @@ +import Component from "@glimmer/component"; +import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; + +export default class ChatStyleguideChatModalNewMessage extends Component { + @service modal; + + @action + openModal() { + return this.modal.show(ChatModalNewMessage); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.hbs new file mode 100644 index 00000000000..496b4784b58 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js new file mode 100644 index 00000000000..106faef111d --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js @@ -0,0 +1,16 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import Component from "@glimmer/component"; +import ChatModalThreadSettings from "discourse/plugins/chat/discourse/components/modal/chat/thread-settings"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; + +export default class ChatStyleguideChatModalThreadSettings extends Component { + @service modal; + + @action + openModal() { + return this.modal.show(ChatModalThreadSettings, { + model: fabricators.thread(), + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.hbs new file mode 100644 index 00000000000..c11dd520807 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.hbs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js new file mode 100644 index 00000000000..afd29aab914 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js @@ -0,0 +1,16 @@ +import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; +import Component from "@glimmer/component"; +import ChatModalToggleChannelStatus from "discourse/plugins/chat/discourse/components/chat/modal/toggle-channel-status"; +import { inject as service } from "@ember/service"; +import { action } from "@ember/object"; + +export default class ChatStyleguideChatModalToggleChannelStatus extends Component { + @service modal; + + @action + openModal() { + return this.modal.show(ChatModalToggleChannelStatus, { + model: fabricators.channel(), + }); + } +} diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/organisms/chat.hbs b/plugins/chat/assets/javascripts/discourse/components/styleguide/organisms/chat.hbs index d37a61138f9..e883457235a 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/organisms/chat.hbs +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/organisms/chat.hbs @@ -3,4 +3,17 @@ - \ No newline at end of file + + +

Modals

+ + + + + + + + + + + \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-archive-modal.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-archive-modal.js deleted file mode 100644 index d46a9f241d0..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-archive-modal.js +++ /dev/null @@ -1,8 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default class ChatChannelArchiveModalController extends Controller.extend( - ModalFunctionality -) { - chatChannel = null; -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-delete-modal.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-delete-modal.js deleted file mode 100644 index ad230c1021b..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-delete-modal.js +++ /dev/null @@ -1,8 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default class ChatChannelDeleteModalController extends Controller.extend( - ModalFunctionality -) { - chatChannel = null; -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-description.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-description.js deleted file mode 100644 index 664a1993bad..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-description.js +++ /dev/null @@ -1,53 +0,0 @@ -import Controller from "@ember/controller"; -import { action, computed } from "@ember/object"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { tracked } from "@glimmer/tracking"; -import { inject as service } from "@ember/service"; - -const DESCRIPTION_MAX_LENGTH = 280; - -export default class ChatChannelEditDescriptionController extends Controller.extend( - ModalFunctionality -) { - @service chatApi; - @tracked editedDescription = this.model.description || ""; - - @computed("model.description", "editedDescription") - get isSaveDisabled() { - return ( - this.model.description === this.editedDescription || - this.editedDescription?.length > DESCRIPTION_MAX_LENGTH - ); - } - - get descriptionMaxLength() { - return DESCRIPTION_MAX_LENGTH; - } - - onClose() { - this.clearFlash(); - } - - @action - onSaveChatChannelDescription() { - return this.chatApi - .updateChannel(this.model.id, { - description: this.editedDescription, - }) - .then((result) => { - this.model.set("description", result.channel.description); - this.send("closeModal"); - }) - .catch((event) => { - if (event.jqXHR?.responseJSON?.errors) { - this.flash(event.jqXHR.responseJSON.errors.join("\n"), "error"); - } - }); - } - - @action - onChangeChatChannelDescription(description) { - this.clearFlash(); - this.editedDescription = description; - } -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-name-slug.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-name-slug.js deleted file mode 100644 index 82bc6c59b2e..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-name-slug.js +++ /dev/null @@ -1,92 +0,0 @@ -import Controller from "@ember/controller"; -import discourseDebounce from "discourse-common/lib/debounce"; -import { ajax } from "discourse/lib/ajax"; -import { cancel } from "@ember/runloop"; -import { action, computed } from "@ember/object"; -import { flashAjaxError } from "discourse/lib/ajax-error"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { inject as service } from "@ember/service"; -export default class ChatChannelEditTitleController extends Controller.extend( - ModalFunctionality -) { - @service chatApi; - editedName = ""; - editedSlug = ""; - autoGeneratedSlug = ""; - - @computed("model.title", "editedName", "editedSlug") - get isSaveDisabled() { - return ( - (this.model.title === this.editedName && - this.model.slug === this.editedSlug) || - this.editedName?.length > this.siteSettings.max_topic_title_length - ); - } - - onShow() { - this.setProperties({ - editedName: this.model.title, - editedSlug: this.model.slug, - }); - } - - onClose() { - this.setProperties({ - editedName: "", - editedSlug: "", - }); - this.clearFlash(); - } - - @action - onSaveChatChannelName() { - return this.chatApi - .updateChannel(this.model.id, { - name: this.editedName, - slug: this.editedSlug || this.autoGeneratedSlug || this.model.slug, - }) - .then((result) => { - this.model.title = result.channel.title; - this.send("closeModal"); - }) - .catch(flashAjaxError(this)); - } - - @action - onChangeChatChannelName(title) { - this.clearFlash(); - this._debouncedGenerateSlug(title); - } - - @action - onChangeChatChannelSlug() { - this.clearFlash(); - this._debouncedGenerateSlug(this.editedName); - } - - _clearAutoGeneratedSlug() { - this.set("autoGeneratedSlug", ""); - } - - _debouncedGenerateSlug(name) { - cancel(this.generateSlugHandler); - this._clearAutoGeneratedSlug(); - if (!name) { - return; - } - this.generateSlugHandler = discourseDebounce( - this, - this._generateSlug, - name, - 300 - ); - } - - // intentionally not showing AJAX error for this, we will autogenerate - // the slug server-side if they leave it blank - _generateSlug(name) { - ajax("/slugs.json", { type: "POST", data: { name } }).then((response) => { - this.set("autoGeneratedSlug", response.slug); - }); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-info-about.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-info-about.js index b21daefbe2c..8748478788f 100644 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-info-about.js +++ b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-info-about.js @@ -1,19 +1,25 @@ import Controller from "@ember/controller"; import { action } from "@ember/object"; import ModalFunctionality from "discourse/mixins/modal-functionality"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; +import ChatModalEditChannelDescription from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-description"; +import ChatModalEditChannelName from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-name"; export default class ChatChannelInfoAboutController extends Controller.extend( ModalFunctionality ) { + @service modal; + @action onEditChatChannelName() { - showModal("chat-channel-edit-name-slug", { model: this.model }); + return this.modal.show(ChatModalEditChannelName, { + model: this.model, + }); } @action onEditChatChannelDescription() { - showModal("chat-channel-edit-description", { + return this.modal.show(ChatModalEditChannelDescription, { model: this.model, }); } diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-selector-modal.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-selector-modal.js deleted file mode 100644 index ac07dd24838..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-selector-modal.js +++ /dev/null @@ -1,12 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { action } from "@ember/object"; - -export default class ChatChannelSelectorModalController extends Controller.extend( - ModalFunctionality -) { - @action - closeSelf() { - this.send("closeModal"); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-toggle.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-toggle.js deleted file mode 100644 index a9cba248a8e..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-toggle.js +++ /dev/null @@ -1,19 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { action } from "@ember/object"; -import { inject as service } from "@ember/service"; - -export default class ChatChannelToggleController extends Controller.extend( - ModalFunctionality -) { - @service chat; - @service router; - - chatChannel = null; - - @action - channelStatusChanged(channel) { - this.send("closeModal"); - this.router.transitionTo("chat.channel", ...channel.routeModels); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-message-move-to-channel-modal.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-message-move-to-channel-modal.js deleted file mode 100644 index 86ebd1e8ab4..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-message-move-to-channel-modal.js +++ /dev/null @@ -1,8 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default class ChatMessageMoveToChannelModalController extends Controller.extend( - ModalFunctionality -) { - chatChannel = null; -} diff --git a/plugins/chat/assets/javascripts/discourse/controllers/chat-thread-settings-modal.js b/plugins/chat/assets/javascripts/discourse/controllers/chat-thread-settings-modal.js deleted file mode 100644 index 7a59f9b99e5..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/chat-thread-settings-modal.js +++ /dev/null @@ -1,8 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default class ChatThreadSettingsModalController extends Controller.extend( - ModalFunctionality -) { - thread = null; -} diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js index f8f87fc89fd..ba6a1b4434b 100644 --- a/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js +++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-keyboard-shortcuts.js @@ -1,6 +1,6 @@ import { withPluginApi } from "discourse/lib/plugin-api"; import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts"; -import ChatNewMessageModal from "discourse/plugins/chat/discourse/components/modal/chat-new-message"; +import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message"; export default { name: "chat-keyboard-shortcuts", @@ -22,10 +22,10 @@ export default { const chatChannelsManager = container.lookup( "service:chat-channels-manager" ); - const openChannelSelector = (e) => { + const openQuickChannelSelector = (e) => { e.preventDefault(); e.stopPropagation(); - modal.show(ChatNewMessageModal); + modal.show(ChatModalNewMessage); }; const handleMoveUpShortcut = (e) => { @@ -126,7 +126,7 @@ export default { withPluginApi("0.12.1", (api) => { api.addKeyboardShortcut( `${PLATFORM_KEY_MODIFIER}+k`, - openChannelSelector, + openQuickChannelSelector, { global: true, help: { diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js index 7b8ab459fb7..7b9886706ca 100644 --- a/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js +++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-sidebar.js @@ -9,7 +9,7 @@ import { emojiUnescape } from "discourse/lib/text"; import { decorateUsername } from "discourse/helpers/decorate-username-selector"; import { until } from "discourse/lib/formatter"; import { inject as service } from "@ember/service"; -import ChatNewMessageModal from "discourse/plugins/chat/discourse/components/modal/chat-new-message"; +import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message"; export default { name: "chat-sidebar", @@ -379,7 +379,7 @@ export default { id: "startDm", title: I18n.t("chat.direct_messages.new"), action: () => { - this.modal.show(ChatNewMessageModal); + this.modal.show(ChatModalNewMessage); }, }, ]; diff --git a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js b/plugins/chat/assets/javascripts/discourse/lib/fabricators.js index 3b90bd00037..a4dba3ff61b 100644 --- a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js +++ b/plugins/chat/assets/javascripts/discourse/lib/fabricators.js @@ -68,6 +68,7 @@ function channelFabricator(args = {}) { description: args.description, chatable: args.chatable || categoryFabricator(), status: CHANNEL_STATUSES.open, + slug: args.chatable?.slug || "general", }, args ) diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-api.js b/plugins/chat/assets/javascripts/discourse/services/chat-api.js index 960376a4b39..54d86607e81 100644 --- a/plugins/chat/assets/javascripts/discourse/services/chat-api.js +++ b/plugins/chat/assets/javascripts/discourse/services/chat-api.js @@ -476,7 +476,8 @@ export default class ChatApi extends Service { * * @param {number} channelId - The ID of the channel. * @param {Array} userIds - The IDs of the users to invite. - * @param {Array} [messageId] - The ID of a message to highlight when opening the notification. + * @param {object} options + * @param {number} options.chat_message_id - A message ID to display in the invite. */ invite(channelId, userIds, options = {}) { return ajax(`/chat/${channelId}/invite`, { @@ -485,6 +486,17 @@ export default class ChatApi extends Service { }); } + /** + * Summarize a channel. + * + * @param {number} channelId - The ID of the channel to summarize. + * @param {object} options + * @param {number} options.since - Number of hours ago the summary should start (1, 3, 6, 12, 24, 72, 168). + */ + summarize(channelId, options = {}) { + return this.#getRequest(`/channels/${channelId}/summarize`, options); + } + get #basePath() { return "/chat/api"; } diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/channel-summary.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/channel-summary.hbs deleted file mode 100644 index c5bf414e9f7..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/channel-summary.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-archive-modal.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-archive-modal.hbs deleted file mode 100644 index bb925b1952b..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-archive-modal.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-delete-modal.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-delete-modal.hbs deleted file mode 100644 index 90820b131a3..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-delete-modal.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-description.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-description.hbs deleted file mode 100644 index 059e2d147bf..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-description.hbs +++ /dev/null @@ -1,32 +0,0 @@ - - - {{i18n "chat.channel_edit_description_modal.description"}} - - - - - - - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name-slug.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name-slug.hbs deleted file mode 100644 index 0d73d0003b8..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name-slug.hbs +++ /dev/null @@ -1,45 +0,0 @@ - -
- - -
- -
- - -
-
- - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name.hbs deleted file mode 100644 index fffffe406c7..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-edit-name.hbs +++ /dev/null @@ -1,22 +0,0 @@ - - - - {{i18n "chat.channel_edit_name_modal.description"}} - - - - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-selector-modal.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-selector-modal.hbs deleted file mode 100644 index 498861076c6..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-selector-modal.hbs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-toggle.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-toggle.hbs deleted file mode 100644 index 121e2c8f424..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-channel-toggle.hbs +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-message-move-to-channel-modal.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-message-move-to-channel-modal.hbs deleted file mode 100644 index 0dcc0c1114d..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-message-move-to-channel-modal.hbs +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-thread-settings-modal.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/chat-thread-settings-modal.hbs deleted file mode 100644 index d94e9d24ae3..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/chat-thread-settings-modal.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/chat/assets/javascripts/discourse/templates/modal/create-channel.hbs b/plugins/chat/assets/javascripts/discourse/templates/modal/create-channel.hbs deleted file mode 100644 index 278f03c1c6a..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/modal/create-channel.hbs +++ /dev/null @@ -1,115 +0,0 @@ - -
- - -
- -
- - -
- -
- - -
- -
- - - - {{#if this.categoryPermissionsHint}} -
- {{this.categoryPermissionsHint}} -
- {{/if}} -
- - {{#if this.autoJoinAvailable}} -
- -
- {{/if}} - - {{#if this.threadingAvailable}} -
- -
- {{/if}} -
- - \ No newline at end of file diff --git a/plugins/chat/assets/stylesheets/common/base-common.scss b/plugins/chat/assets/stylesheets/common/base-common.scss index ee156bf2aaa..884ca7aac50 100644 --- a/plugins/chat/assets/stylesheets/common/base-common.scss +++ b/plugins/chat/assets/stylesheets/common/base-common.scss @@ -16,19 +16,6 @@ html.ios-device.keyboard-visible body #main-outlet .full-page-chat { padding-bottom: 0.2rem; } -.chat-message-move-to-channel-modal-modal { - .modal-inner-container { - .chat-move-message-channel-chooser { - width: 100%; - .category-chat-badge { - .d-icon { - color: inherit; - } - } - } - } -} - .uppy-is-drag-over .chat-composer .drop-a-file { display: flex; position: absolute; @@ -315,38 +302,6 @@ body.has-full-page-chat { } } -.chat-channel-archive-modal-inner { - .chat-to-topic-selector { - width: 500px; - height: 300px; - } - - .radios { - margin-bottom: 10px; - display: flex; - flex-direction: row; - - .radio-label { - margin-right: 10px; - } - } - - details { - margin-bottom: 9px; - } - - input[type="text"], - .select-kit.combo-box.category-chooser { - width: 100%; - } -} - -.chat-channel-archive-modal-inner { - .chat-to-topic-selector { - width: auto; - } -} - .user-preferences .chat-setting .controls { margin-bottom: 0; } diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-info.scss b/plugins/chat/assets/stylesheets/common/chat-channel-info.scss index b3f10acf39b..be5dee75b81 100644 --- a/plugins/chat/assets/stylesheets/common/chat-channel-info.scss +++ b/plugins/chat/assets/stylesheets/common/chat-channel-info.scss @@ -139,25 +139,3 @@ input.channel-members-view__search-input { padding: 0.5rem 0; color: var(--primary-medium); } - -// Channel info edit description modal -.chat-channel-edit-description-modal { - .exceeded-word-count { - .chat-channel-edit-description-modal__description-input { - outline: 1px solid var(--danger); - border: 1px solid var(--danger); - } - } -} - -.chat-channel-edit-description-modal__description-input { - display: flex; - margin: 0; - min-height: 200px; -} - -.chat-channel-edit-description-modal__description { - display: flex; - padding-bottom: 0.75rem; - color: var(--primary-medium); -} diff --git a/plugins/chat/assets/stylesheets/common/chat-modal-archive-channel.scss b/plugins/chat/assets/stylesheets/common/chat-modal-archive-channel.scss new file mode 100644 index 00000000000..aff98188d14 --- /dev/null +++ b/plugins/chat/assets/stylesheets/common/chat-modal-archive-channel.scss @@ -0,0 +1,25 @@ +.chat-modal-archive-channel { + .chat-to-topic-selector { + width: auto; + height: 300px; + } + + .radios { + margin-bottom: 10px; + display: flex; + flex-direction: row; + + .radio-label { + margin-right: 10px; + } + } + + details { + margin-bottom: 9px; + } + + input[type="text"], + .select-kit.combo-box.category-chooser { + width: 100%; + } +} diff --git a/plugins/chat/assets/stylesheets/common/channel-summary-modal.scss b/plugins/chat/assets/stylesheets/common/chat-modal-channel-summary.scss similarity index 80% rename from plugins/chat/assets/stylesheets/common/channel-summary-modal.scss rename to plugins/chat/assets/stylesheets/common/chat-modal-channel-summary.scss index b1ce698e8ec..3f795455cff 100644 --- a/plugins/chat/assets/stylesheets/common/channel-summary-modal.scss +++ b/plugins/chat/assets/stylesheets/common/chat-modal-channel-summary.scss @@ -1,4 +1,4 @@ -.channel-summary-modal { +.chat-modal-channel-summary { .summarization-since, .summary-area { margin: 10px 0 10px 0; diff --git a/plugins/chat/assets/stylesheets/common/create-channel-modal.scss b/plugins/chat/assets/stylesheets/common/chat-modal-create-channel.scss similarity index 83% rename from plugins/chat/assets/stylesheets/common/create-channel-modal.scss rename to plugins/chat/assets/stylesheets/common/chat-modal-create-channel.scss index f7385374d6a..e1dfc3956f9 100644 --- a/plugins/chat/assets/stylesheets/common/create-channel-modal.scss +++ b/plugins/chat/assets/stylesheets/common/chat-modal-create-channel.scss @@ -1,4 +1,4 @@ -.create-channel-modal { +.chat-modal-create-channel { .modal-inner-container { width: 500px; } @@ -9,7 +9,7 @@ } .select-kit.combo-box, - .create-channel__input, + &__input, #choose-topic-title { width: 100%; margin-bottom: 0; @@ -22,18 +22,18 @@ } } - .create-channel__hint { + &__hint { font-size: var(--font-down-1); padding-top: 0.25rem; color: var(--secondary-low); } - .create-channel__control, + &__control, .edit-channel-control { margin-bottom: 1rem; } - .create-channel__label-description { + &__label-description { margin: 0; padding-top: 0.25rem; color: var(--secondary-low); diff --git a/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-description.scss b/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-description.scss new file mode 100644 index 00000000000..359f6e8144b --- /dev/null +++ b/plugins/chat/assets/stylesheets/common/chat-modal-edit-channel-description.scss @@ -0,0 +1,20 @@ +.chat-modal-edit-channel-description { + .exceeded-word-count { + .chat-modal-edit-channel-description__description-input { + outline: 1px solid var(--danger); + border: 1px solid var(--danger); + } + } + + &__description-input { + display: flex; + margin: 0; + min-height: 200px; + } + + &__description { + display: flex; + padding-bottom: 0.75rem; + color: var(--primary-medium); + } +} diff --git a/plugins/chat/assets/stylesheets/common/chat-modal-move-message-to-channel.scss b/plugins/chat/assets/stylesheets/common/chat-modal-move-message-to-channel.scss new file mode 100644 index 00000000000..2f9abebc49e --- /dev/null +++ b/plugins/chat/assets/stylesheets/common/chat-modal-move-message-to-channel.scss @@ -0,0 +1,10 @@ +.chat-modal-move-message-to-channel { + &__channel-chooser { + width: 100%; + .category-chat-badge { + .d-icon { + color: inherit; + } + } + } +} diff --git a/plugins/chat/assets/stylesheets/common/chat-new-message-modal.scss b/plugins/chat/assets/stylesheets/common/chat-modal-new-message.scss similarity index 95% rename from plugins/chat/assets/stylesheets/common/chat-new-message-modal.scss rename to plugins/chat/assets/stylesheets/common/chat-modal-new-message.scss index 670766913e2..da33bf6813e 100644 --- a/plugins/chat/assets/stylesheets/common/chat-new-message-modal.scss +++ b/plugins/chat/assets/stylesheets/common/chat-modal-new-message.scss @@ -1,4 +1,4 @@ -.chat-new-message-modal { +.chat-modal-new-message { & + .modal-backdrop { opacity: 1; background: transparent; diff --git a/plugins/chat/assets/stylesheets/common/index.scss b/plugins/chat/assets/stylesheets/common/index.scss index 499dc84e46f..39e9619177f 100644 --- a/plugins/chat/assets/stylesheets/common/index.scss +++ b/plugins/chat/assets/stylesheets/common/index.scss @@ -41,7 +41,6 @@ @import "chat-upload-drop-zone"; @import "chat-transcript"; @import "core-extensions"; -@import "create-channel-modal"; @import "dc-filter-input"; @import "full-page-chat-header"; @import "incoming-chat-webhooks"; @@ -53,9 +52,14 @@ @import "chat-thread-list-header"; @import "chat-thread-unread-indicator"; @import "chat-thread-participants"; -@import "channel-summary-modal"; @import "chat-message-mention-warning"; @import "chat-message-error"; -@import "chat-new-message-modal"; @import "chat-message-creator"; @import "chat-user-avatar"; +@import "chat-modal-new-message"; +@import "chat-modal-archive-channel"; +@import "chat-modal-edit-channel-description"; +@import "chat-modal-create-channel"; +@import "chat-modal-create-channel"; +@import "chat-modal-channel-summary"; +@import "chat-modal-move-message-to-channel"; diff --git a/plugins/chat/assets/stylesheets/mobile/chat-modal-thread-settings.scss b/plugins/chat/assets/stylesheets/mobile/chat-modal-thread-settings.scss new file mode 100644 index 00000000000..db511f4e7d0 --- /dev/null +++ b/plugins/chat/assets/stylesheets/mobile/chat-modal-thread-settings.scss @@ -0,0 +1,9 @@ +.modal-chat-thread-settings { + .modal-inner-container { + width: 98%; + } + + &__title-input { + width: 100%; + } +} diff --git a/plugins/chat/assets/stylesheets/mobile/chat-thread-settings-modal.scss b/plugins/chat/assets/stylesheets/mobile/chat-thread-settings-modal.scss deleted file mode 100644 index b27bcfd979a..00000000000 --- a/plugins/chat/assets/stylesheets/mobile/chat-thread-settings-modal.scss +++ /dev/null @@ -1,9 +0,0 @@ -.chat-thread-settings-modal-modal { - .modal-inner-container { - width: 98%; - - .thread-title-input { - width: 100%; - } - } -} diff --git a/plugins/chat/assets/stylesheets/mobile/index.scss b/plugins/chat/assets/stylesheets/mobile/index.scss index c4de1d951d3..f9fdace3e91 100644 --- a/plugins/chat/assets/stylesheets/mobile/index.scss +++ b/plugins/chat/assets/stylesheets/mobile/index.scss @@ -11,6 +11,6 @@ @import "chat-side-panel"; @import "chat-thread"; @import "chat-threads-list"; -@import "chat-thread-settings-modal"; +@import "chat-modal-thread-settings"; @import "chat-message-thread-indicator"; @import "chat-message-creator"; diff --git a/plugins/chat/spec/system/channel_about_page_spec.rb b/plugins/chat/spec/system/channel_about_page_spec.rb index 098b30a1310..550fa4c3ee4 100644 --- a/plugins/chat/spec/system/channel_about_page_spec.rb +++ b/plugins/chat/spec/system/channel_about_page_spec.rb @@ -97,12 +97,12 @@ RSpec.describe "Channel - Info - About page", type: :system do find(".edit-description-btn").click expect(page).to have_selector( - ".chat-channel-edit-description-modal__description-input", + ".chat-modal-edit-channel-description__description-input", text: channel_1.description, ) description = "A new description" - find(".chat-channel-edit-description-modal__description-input").fill_in(with: description) + find(".chat-modal-edit-channel-description__description-input").fill_in(with: description) find(".create").click expect(page).to have_content(description) diff --git a/plugins/chat/spec/system/chat_summarization_spec.rb b/plugins/chat/spec/system/chat_summarization_spec.rb index df504058e7d..57401b57559 100644 --- a/plugins/chat/spec/system/chat_summarization_spec.rb +++ b/plugins/chat/spec/system/chat_summarization_spec.rb @@ -33,7 +33,7 @@ RSpec.describe "Summarize a channel since your last visit", type: :system, js: t find(".chat-composer-dropdown__trigger-btn").click find(".chat-composer-dropdown__action-btn.channel-summary").click - expect(page.has_css?(".channel-summary-modal", wait: 5)).to eq(true) + expect(page.has_css?(".chat-modal-channel-summary")).to eq(true) find(".summarization-since").click find(".select-kit-row[data-value=\"3\"]").click diff --git a/plugins/chat/spec/system/create_channel_spec.rb b/plugins/chat/spec/system/create_channel_spec.rb index 45b9959b19a..2b6fe007def 100644 --- a/plugins/chat/spec/system/create_channel_spec.rb +++ b/plugins/chat/spec/system/create_channel_spec.rb @@ -148,7 +148,7 @@ RSpec.describe "Create channel", type: :system do context "for a public category" do before do channel_modal.select_category(category_1) - find(".-auto-join .create-channel__label").click + find(".-auto-join .chat-modal-create-channel__label").click channel_modal.click_primary_button end @@ -172,7 +172,7 @@ RSpec.describe "Create channel", type: :system do it "does nothing if no is clicked" do dialog.click_no - expect(page).to have_css(".create-channel-modal") + expect(page).to have_css(".chat-modal-create-channel") expect(Chat::Channel.exists?(chatable_id: category_1.id)).to eq(false) end end @@ -185,7 +185,7 @@ RSpec.describe "Create channel", type: :system do before do group_1.add(user_1) channel_modal.select_category(private_category) - find(".-auto-join .create-channel__label").click + find(".-auto-join .chat-modal-create-channel__label").click channel_modal.click_primary_button end diff --git a/plugins/chat/spec/system/move_message_to_channel_spec.rb b/plugins/chat/spec/system/move_message_to_channel_spec.rb index 7757b93fcca..c98121a6da4 100644 --- a/plugins/chat/spec/system/move_message_to_channel_spec.rb +++ b/plugins/chat/spec/system/move_message_to_channel_spec.rb @@ -79,7 +79,7 @@ RSpec.describe "Move message to channel", type: :system do chat_page.visit_channel(channel_1) channel_page.messages.select(message_1) channel_page.selection_management.move - find(".chat-move-message-channel-chooser").click + find(".chat-modal-move-message-to-channel__channel-chooser").click find("[data-value='#{channel_2.id}']").click click_button(I18n.t("js.chat.move_to_channel.confirm_move")) diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rb index a79d717b4a7..c95069f2814 100644 --- a/plugins/chat/spec/system/page_objects/chat/chat.rb +++ b/plugins/chat/spec/system/page_objects/chat/chat.rb @@ -27,7 +27,7 @@ module PageObjects def open_new_message send_keys([PLATFORM_KEY_MODIFIER, "k"]) - find(".chat-new-message-modal") + find(".chat-modal-new-message") end def has_drawer?(channel_id: nil, expanded: true) diff --git a/plugins/chat/spec/system/page_objects/chat/chat_channel_about.rb b/plugins/chat/spec/system/page_objects/chat/chat_channel_about.rb index 795893346a7..a28836bb59f 100644 --- a/plugins/chat/spec/system/page_objects/chat/chat_channel_about.rb +++ b/plugins/chat/spec/system/page_objects/chat/chat_channel_about.rb @@ -3,7 +3,7 @@ module PageObjects module Pages class ChatChannelAbout < PageObjects::Pages::Base - EDIT_MODAL_SELECTOR = ".chat-channel-edit-name-slug-modal" + EDIT_MODAL_SELECTOR = ".chat-modal-edit-channel-name" def open_edit_modal click_button(class: "edit-name-slug-btn") diff --git a/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb b/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb index 8a02518453e..896c3b27776 100644 --- a/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb +++ b/plugins/chat/spec/system/page_objects/chat/components/message_creator.rb @@ -6,7 +6,7 @@ module PageObjects class MessageCreator < PageObjects::Components::Base attr_reader :context - SELECTOR = ".chat-new-message-modal" + SELECTOR = ".chat-modal-new-message" def component find(SELECTOR) diff --git a/plugins/chat/spec/system/page_objects/modals/chat_channel_create.rb b/plugins/chat/spec/system/page_objects/modals/chat_channel_create.rb index 9b68c680fdc..228760729cb 100644 --- a/plugins/chat/spec/system/page_objects/modals/chat_channel_create.rb +++ b/plugins/chat/spec/system/page_objects/modals/chat_channel_create.rb @@ -9,11 +9,11 @@ module PageObjects end def create_channel_hint - find(".create-channel__hint") + find(".chat-modal-create-channel__hint") end def slug_input - find(".-slug .create-channel__input") + find(".-slug .chat-modal-create-channel__input") end def has_create_hint?(content) @@ -21,23 +21,23 @@ module PageObjects end def has_threading_toggle? - has_selector?(".create-channel__control.-threading-toggle") + has_selector?(".chat-modal-create-channel__control.-threading-toggle") end def fill_name(name) - fill_in("channel-name", with: name) + fill_in("name", with: name) end def fill_slug(slug) - fill_in("channel-slug", with: slug) + fill_in("slug", with: slug) end def fill_description(description) - fill_in("channel-description", with: description) + fill_in("description", with: description) end def has_name_prefilled?(name) - has_field?("channel-name", with: name) + has_field?("name", with: name) end end end diff --git a/plugins/chat/spec/system/thread_list/full_page_spec.rb b/plugins/chat/spec/system/thread_list/full_page_spec.rb index 6851672cbc6..89cdf66a026 100644 --- a/plugins/chat/spec/system/thread_list/full_page_spec.rb +++ b/plugins/chat/spec/system/thread_list/full_page_spec.rb @@ -150,7 +150,7 @@ describe "Thread list in side panel | full page", type: :system do open_thread_list thread_list_page.item_by_id(thread_1.id).click thread_page.header.open_settings - find(".thread-title-input").fill_in(with: new_title) + find(".chat-modal-thread-settings__title-input").fill_in(with: new_title) find(".modal-footer .btn-primary").click expect(thread_page.header).to have_title_content(new_title) end @@ -161,7 +161,7 @@ describe "Thread list in side panel | full page", type: :system do open_thread_list thread_list_page.item_by_id(thread_1.id).click thread_page.header.open_settings - find(".thread-title-input").fill_in(with: new_title) + find(".chat-modal-thread-settings__title-input").fill_in(with: new_title) find(".modal-footer .btn-primary").click expect(thread_page.header).to have_title_content(new_title) end diff --git a/plugins/chat/test/javascripts/components/chat-channel-delete-modal-inner-test.js b/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js similarity index 64% rename from plugins/chat/test/javascripts/components/chat-channel-delete-modal-inner-test.js rename to plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js index 72a9d84d3be..847a5162b7e 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-delete-modal-inner-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js @@ -6,24 +6,21 @@ import { render } from "@ember/test-helpers"; import { module, test } from "qunit"; module( - "Discourse Chat | Component | chat-channel-delete-modal-inner", + "Discourse Chat | Component | ", function (hooks) { setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.set( - "channel", - fabricators.channel({ - title: ``, - }) - ); + this.channel = fabricators.channel({ + title: ``, + }); await render( - hbs`` + hbs`` ); assert.true( - query(".chat-channel-delete-modal-instructions").innerHTML.includes( + query(".chat-modal-archive-channel").innerHTML.includes( "<script>someeviltitle</script>" ) ); diff --git a/plugins/chat/test/javascripts/components/chat-channel-archive-modal-inner-test.js b/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js similarity index 65% rename from plugins/chat/test/javascripts/components/chat-channel-archive-modal-inner-test.js rename to plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js index 6995574c416..2d441aa2619 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-archive-modal-inner-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js @@ -6,24 +6,21 @@ import { render } from "@ember/test-helpers"; import { module, test } from "qunit"; module( - "Discourse Chat | Component | chat-channel-archive-modal-inner", + "Discourse Chat | Component | ", function (hooks) { setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.set( - "channel", - fabricators.channel({ - title: ``, - }) - ); + this.channel = fabricators.channel({ + title: ``, + }); await render( - hbs`` + hbs`` ); assert.true( - query(".chat-channel-archive-modal-instructions").innerHTML.includes( + query(".chat-modal-delete-channel__instructions").innerHTML.includes( "<script>someeviltitle</script>" ) ); diff --git a/plugins/chat/test/javascripts/components/chat-message-move-to-channel-modal-inner-test.js b/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js similarity index 54% rename from plugins/chat/test/javascripts/components/chat-message-move-to-channel-modal-inner-test.js rename to plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js index e40a49f7819..086e8756a79 100644 --- a/plugins/chat/test/javascripts/components/chat-message-move-to-channel-modal-inner-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js @@ -6,28 +6,25 @@ import { render } from "@ember/test-helpers"; import { module, test } from "qunit"; module( - "Discourse Chat | Component | chat-message-move-to-channel-modal-inner", + "Discourse Chat | Component | ", function (hooks) { setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.set( - "channel", - fabricators.channel({ title: "" }) - ); - this.set("chat", { publicChannels: [this.channel] }); - this.set("selectedMessageIds", [1]); + this.channel = fabricators.channel({ + title: "", + }); + this.selectedMessageIds = [this.channel.id]; await render(hbs` - `); assert.true( - query(".chat-message-move-to-channel-modal-inner").innerHTML.includes( + query(".chat-modal-move-message-to-channel").innerHTML.includes( "<script>someeviltitle</script>" ) ); diff --git a/plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls/row.hbs b/plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls/row.hbs index 59f0c996c77..20f1b586a6d 100644 --- a/plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls/row.hbs +++ b/plugins/styleguide/assets/javascripts/discourse/components/styleguide/controls/row.hbs @@ -1,5 +1,7 @@ - {{@name}} + {{#if @name}} + {{@name}} + {{/if}} {{yield}}