UX: Use topic list bulk select toggle for user messages list. (#13614)

UX: Use topic list bulk select toggle for user messages list. (#13614)

diff --git a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js
index 3cc26e8..22f99d2 100644
--- a/app/assets/javascripts/discourse/app/controllers/user-private-messages.js
+++ b/app/assets/javascripts/discourse/app/controllers/user-private-messages.js
@@ -1,67 +1,28 @@
 import Controller, { inject as controller } from "@ember/controller";
 import { action } from "@ember/object";
 import { alias, and, equal } from "@ember/object/computed";
-import I18n from "I18n";
-import Topic from "discourse/models/topic";
-import bootbox from "bootbox";
 import discourseComputed from "discourse-common/utils/decorators";
 import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings";
 
 export default Controller.extend({
-  userTopicsList: controller("user-topics-list"),
   user: controller(),
 
   pmView: false,
   viewingSelf: alias("user.viewingSelf"),
   isGroup: equal("pmView", "groups"),
   currentPath: alias("router._router.currentPath"),
-  selected: alias("userTopicsList.selected"),
-  bulkSelectEnabled: alias("userTopicsList.bulkSelectEnabled"),
-  showToggleBulkSelect: true,
   pmTaggingEnabled: alias("site.can_tag_pms"),
   tagId: null,
 
   showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"),
 
-  @discourseComputed("selected.[]", "bulkSelectEnabled")
-  hasSelection(selected, bulkSelectEnabled) {
-    return bulkSelectEnabled && selected && selected.length > 0;
-  },
-
   @discourseComputed("viewingSelf", "pmView", "currentUser.admin")
   showWarningsWarning(viewingSelf, pmView, isAdmin) {
     return pmView === VIEW_NAME_WARNINGS && !viewingSelf && !isAdmin;
   },
 
-  bulkOperation(operation) {
-    const selected = this.selected;
-    let params = { type: operation };
-    if (this.isGroup) {
-      params.group = this.groupFilter;
-    }
-
-    Topic.bulkOperation(selected, params).then(
-      () => {
-        const model = this.get("userTopicsList.model");
-        const topics = model.get("topics");
-        topics.removeObjects(selected);
-        selected.clear();
-        model.loadMore();
-      },
-      () => {
-        bootbox.alert(I18n.t("user.messages.failed_to_move"));
-      }
-    );
-  },
-
   @action
   changeGroupNotificationLevel(notificationLevel) {
     this.group.setNotification(notificationLevel, this.get("user.model.id"));
   },
-
-  @action
-  toggleBulkSelect() {
-    this.selected.clear();
-    this.toggleProperty("bulkSelectEnabled");
-  },
 });
diff --git a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js
index 1196916..61b3c11 100644
--- a/app/assets/javascripts/discourse/app/controllers/user-topics-list.js
+++ b/app/assets/javascripts/discourse/app/controllers/user-topics-list.js
@@ -1,8 +1,9 @@
 import Controller, { inject as controller } from "@ember/controller";
 import discourseComputed, { observes } from "discourse-common/utils/decorators";
+import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
 
 // Lists of topics on a user's page.
-export default Controller.extend({
+export default Controller.extend(BulkTopicSelection, {
   application: controller(),
 
   hideCategory: false,
diff --git a/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js b/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js
index 102e3cf..caec153 100644
--- a/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js
+++ b/app/assets/javascripts/discourse/app/routes/build-private-messages-route.js
@@ -44,12 +44,12 @@ export default (viewName, path, channel) => {
         canBulkSelect: true,
         tagsForUser: this.modelFor("user").get("username_lower"),
         selected: [],
+        showToggleBulkSelect: true,
       });
 
       this.controllerFor("user-private-messages").setProperties({
         archive: false,
         pmView: viewName,
-        showToggleBulkSelect: true,
       });
 
       this.searchService.set("contextType", "private_messages");
diff --git a/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js b/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js
index 3cbda90..24f3a94 100644
--- a/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js
+++ b/app/assets/javascripts/discourse/app/routes/user-private-messages-tags.js
@@ -26,8 +26,13 @@ export default DiscourseRoute.extend({
         : ["count:desc", "id"],
       tagsForUser: this.modelFor("user").get("username_lower"),
     });
-    this.controllerFor("user-private-messages").setProperties({
+
+    this.controllerFor("user-topics-list").setProperties({
       showToggleBulkSelect: false,
+      selected: [],
+    });
+
+    this.controllerFor("user-private-messages").setProperties({
       pmView: "tags",
     });
   },
diff --git a/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs
index 98a64a0..ed237ac 100644
--- a/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/basic-topic-list.hbs
@@ -20,6 +20,8 @@
       tagsForUser=tagsForUser
       onScroll=onScroll
       scrollOnLoad=scrollOnLoad
+      toggleBulkSelect=toggleBulkSelect
+      updateAutoAddTopicsToBulkSelect=updateAutoAddTopicsToBulkSelect
     }}
   {{else}}
     {{#unless loadingMore}}
diff --git a/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs b/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs
index adeab89..ba90678 100644
--- a/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs
+++ b/app/assets/javascripts/discourse/app/templates/user-topics-list.hbs
@@ -1,3 +1,9 @@
+{{#unless site.mobileView}}
+  {{#if showToggleBulkSelect}}
+    {{bulk-select-button selected=selected action=(route-action "refresh")}}
+  {{/if}}
+{{/unless}}
+
 {{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
   {{basic-topic-list topicList=model
                      hideCategory=hideCategory
@@ -9,7 +15,10 @@
                      showInserted=(action "showInserted")
                      tagsForUser=tagsForUser
                      onScroll=saveScrollPosition
-                     scrollOnLoad=true}}
+                     canBulkSelect=canBulkSelect
+                     scrollOnLoad=true
+                     toggleBulkSelect=(action "toggleBulkSelect")
+                     updateAutoAddTopicsToBulkSelect=(action "updateAutoAddTopicsToBulkSelect")}}
 
   {{conditional-loading-spinner condition=model.loadingMore}}
 {{/load-more}}
diff --git a/app/assets/javascripts/discourse/app/templates/user/messages.hbs b/app/assets/javascripts/discourse/app/templates/user/messages.hbs
index 23eaded..5a845ea 100644
--- a/app/assets/javascripts/discourse/app/templates/user/messages.hbs
+++ b/app/assets/javascripts/discourse/app/templates/user/messages.hbs
@@ -57,13 +57,6 @@
 
 <section class="user-content">
   <div class="list-actions">
-    {{#unless site.mobileView}}
-      {{#if showToggleBulkSelect}}
-        {{d-button icon="list" class="btn-default bulk-select" title="topics.bulk.toggle" action=(action "toggleBulkSelect")}}
-        {{bulk-select-button selected=selected action=(route-action "refresh")}}
-      {{/if}}
-    {{/unless}}
-
     {{#if site.mobileView}}
       {{#if showNewPM}}
         {{d-button
@@ -74,12 +67,6 @@
       {{/if}}
     {{/if}}
 
-    {{#if bulkSelectEnabled}}
-      {{bulk-select-all
-        class="btn-default btn-select-all"
-        label="user.messages.select_all"}}
-    {{/if}}
-
     {{#if isGroup}}
       {{group-notifications-button
         value=group.group_user.notification_level

[... diff too long, it was truncated ...]

GitHub sha: 43058db3cae5f9a06e62204253a8be0404948425

This commit appears in #13614 which was approved by eviltrout. It was merged by tgxworld.