From b5c1132546028d2a39f85da4e58d2e7979233efb Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 26 Jul 2022 15:36:35 -0400 Subject: [PATCH] UX: add bulk-select to mobile topic lists (#15386) --- .../app/components/bulk-select-toggle.js | 17 +++ .../discourse/app/components/d-navigation.js | 12 ++ .../discourse/app/components/topic-list.js | 4 +- .../components/bulk-select-toggle.hbs | 1 + .../app/templates/components/d-navigation.hbs | 3 + .../app/templates/components/topic-list.hbs | 33 ++--- .../app/templates/mobile/discovery/topics.hbs | 19 ++- .../templates/mobile/list/topic-list-item.hbr | 8 +- .../templates/topic-list-header-column.hbr | 2 +- .../discourse/app/templates/user/messages.hbs | 9 +- .../mobile-topic-bulk-actions-test.js | 132 ++++++++++++++++++ app/assets/stylesheets/mobile/topic-list.scss | 57 ++++++++ 12 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/bulk-select-toggle.js create mode 100644 app/assets/javascripts/discourse/app/templates/components/bulk-select-toggle.hbs create mode 100644 app/assets/javascripts/discourse/tests/acceptance/mobile-topic-bulk-actions-test.js diff --git a/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js new file mode 100644 index 00000000000..80ddbc7decc --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/bulk-select-toggle.js @@ -0,0 +1,17 @@ +import Component from "@ember/component"; +import { action } from "@ember/object"; +import { getOwner } from "discourse-common/lib/get-owner"; + +export default Component.extend({ + parentController: null, + + @action + toggleBulkSelect() { + const controller = getOwner(this).lookup( + `controller:${this.parentController}` + ); + const selection = controller.selected; + controller.toggleProperty("bulkSelectEnabled"); + selection.clear(); + }, +}); diff --git a/app/assets/javascripts/discourse/app/components/d-navigation.js b/app/assets/javascripts/discourse/app/components/d-navigation.js index 266bbf7c4d5..32f8756b42b 100644 --- a/app/assets/javascripts/discourse/app/components/d-navigation.js +++ b/app/assets/javascripts/discourse/app/components/d-navigation.js @@ -4,6 +4,7 @@ import NavItem from "discourse/models/nav-item"; import bootbox from "bootbox"; import discourseComputed from "discourse-common/utils/decorators"; import { NotificationLevels } from "discourse/lib/notification-levels"; +import { getOwner } from "discourse-common/lib/get-owner"; import { inject as service } from "@ember/service"; export default Component.extend(FilterModeMixin, { @@ -128,6 +129,17 @@ export default Component.extend(FilterModeMixin, { }); }, + @discourseComputed("filterType") + notCategoriesRoute(filterType) { + return filterType !== "categories"; + }, + + @discourseComputed() + canBulk() { + const controller = getOwner(this).lookup("controller:discovery/topics"); + return controller.canBulkSelect; + }, + actions: { changeCategoryNotificationLevel(notificationLevel) { this.category.setNotification(notificationLevel); diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js index 74fe6518cfb..22b01c759d4 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list.js +++ b/app/assets/javascripts/discourse/app/components/topic-list.js @@ -1,4 +1,4 @@ -import { alias, and, reads } from "@ember/object/computed"; +import { alias, and } from "@ember/object/computed"; import discourseComputed, { observes } from "discourse-common/utils/decorators"; import Component from "@ember/component"; import LoadMore from "discourse/mixins/load-more"; @@ -34,8 +34,6 @@ export default Component.extend(LoadMore, { return !!this.changeSort; }, - skipHeader: reads("site.mobileView"), - @discourseComputed("order") showLikes(order) { return order === "likes"; diff --git a/app/assets/javascripts/discourse/app/templates/components/bulk-select-toggle.hbs b/app/assets/javascripts/discourse/app/templates/components/bulk-select-toggle.hbs new file mode 100644 index 00000000000..4a48158dc45 --- /dev/null +++ b/app/assets/javascripts/discourse/app/templates/components/bulk-select-toggle.hbs @@ -0,0 +1 @@ + diff --git a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs index 8b7151b7be3..2e793cfaa8b 100644 --- a/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/d-navigation.hbs @@ -6,6 +6,9 @@ {{/unless}}