FEATURE: new dismiss button for combined new and unread view (#21817)

Display modal for combined new and unread view with options:
- [x] Dismiss new topics
- [x] Dismiss new posts
- [ ] Stop tracking these topics so they stop appearing in my new list
This commit is contained in:
Krzysztof Kotlarek
2023-06-07 10:06:57 +10:00
committed by GitHub
parent 899969fd5d
commit af74cf5c77
11 changed files with 374 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import { alias, empty, equal, gt, not, readOnly } from "@ember/object/computed";
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
import DismissTopics from "discourse/mixins/dismiss-topics";
import DiscoveryController from "discourse/controllers/discovery";
import I18n from "I18n";
import Topic from "discourse/models/topic";
@@ -56,6 +57,32 @@ const controllerOpts = {
return this._isFilterPage(filter, "new") && topicsLength > 0;
},
callResetNew(dismissPosts = false, dismissTopics = false, untrack = false) {
const tracked =
(this.router.currentRoute.queryParams["f"] ||
this.router.currentRoute.queryParams["filter"]) === "tracked";
let topicIds = this.selected
? this.selected.map((topic) => topic.id)
: null;
Topic.resetNew(this.category, !this.noSubcategories, {
tracked,
topicIds,
dismissPosts,
dismissTopics,
untrack,
}).then((result) => {
if (result.topic_ids) {
this.topicTrackingState.removeTopics(result.topic_ids);
}
this.send(
"refresh",
tracked ? { skipResettingParams: ["filter", "f"] } : {}
);
});
},
// Show newly inserted topics
@action
showInserted(event) {
@@ -114,26 +141,6 @@ const controllerOpts = {
}
});
},
resetNew() {
const tracked =
(this.router.currentRoute.queryParams["f"] ||
this.router.currentRoute.queryParams["filter"]) === "tracked";
let topicIds = this.selected
? this.selected.map((topic) => topic.id)
: null;
Topic.resetNew(this.category, !this.noSubcategories, {
tracked,
topicIds,
}).then(() =>
this.send(
"refresh",
tracked ? { skipResettingParams: ["filter", "f"] } : {}
)
);
},
},
afterRefresh(filter, list, listModel = list) {
@@ -213,4 +220,8 @@ const controllerOpts = {
},
};
export default DiscoveryController.extend(controllerOpts, BulkTopicSelection);
export default DiscoveryController.extend(
controllerOpts,
BulkTopicSelection,
DismissTopics
);

View File

@@ -0,0 +1,13 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action } from "@ember/object";
export default class DismissNewController extends Controller.extend(
ModalFunctionality
) {
@action
dismiss() {
this.dismissCallback();
this.send("closeModal");
}
}

View File

@@ -2,6 +2,7 @@ import DiscoverySortableController from "discourse/controllers/discovery-sortabl
import { inject as controller } from "@ember/controller";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
import DismissTopics from "discourse/mixins/dismiss-topics";
import FilterModeMixin from "discourse/mixins/filter-mode";
import I18n from "I18n";
import NavItem from "discourse/models/nav-item";
@@ -13,6 +14,7 @@ import { inject as service } from "@ember/service";
export default DiscoverySortableController.extend(
BulkTopicSelection,
DismissTopics,
FilterModeMixin,
{
application: controller(),
@@ -91,8 +93,7 @@ export default DiscoverySortableController.extend(
return this._isFilterPage(filter, "new") && topicsLength > 0;
},
@action
resetNew() {
callResetNew(dismissPosts = false, dismissTopics = false, untrack = false) {
const tracked =
(this.router.currentRoute.queryParams["f"] ||
this.router.currentRoute.queryParams["filter"]) === "tracked";
@@ -103,9 +104,15 @@ export default DiscoverySortableController.extend(
tracked,
tag: this.tag,
topicIds,
}).then(() =>
this.refresh(tracked ? { skipResettingParams: ["filter", "f"] } : {})
);
dismissPosts,
dismissTopics,
untrack,
}).then((result) => {
if (result.topic_ids) {
this.topicTrackingState.removeTopics(result.topic_ids);
}
this.refresh(tracked ? { skipResettingParams: ["filter", "f"] } : {});
});
},
@action

View File

@@ -0,0 +1,30 @@
import Mixin from "@ember/object/mixin";
import User from "discourse/models/user";
import showModal from "discourse/lib/show-modal";
import I18n from "I18n";
export default Mixin.create({
actions: {
resetNew() {
const user = User.current();
if (!user.new_new_view_enabled) {
return this.callResetNew();
}
const controller = showModal("dismiss-new", {
model: {
dismissTopics: true,
dismissPosts: true,
},
titleTranslated: I18n.t("topics.bulk.dismiss_new_modal.title"),
});
controller.set("dismissCallback", () => {
this.callResetNew(
controller.model.dismissPosts,
controller.model.dismissTopics,
controller.model.untrack
);
});
},
},
});

View File

@@ -851,6 +851,18 @@ Topic.reopenClass({
data.topic_ids = topicIds;
}
if (opts.dismissPosts) {
data.dismiss_posts = opts.dismissPosts;
}
if (opts.dismissTopics) {
data.dismiss_topics = opts.dismissTopics;
}
if (opts.untrack) {
data.untrack = opts.untrack;
}
return ajax("/topics/reset-new", { type: "PUT", data });
},

View File

@@ -0,0 +1,29 @@
<DModalBody>
<p>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.topics"
@checked={{this.model.dismissTopics}}
@class="dismiss-topics"
/>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.posts"
@checked={{this.model.dismissPosts}}
@class="dismiss-posts"
/>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.untrack"
@checked={{this.model.untrack}}
@class="untrack"
/>
</p>
</DModalBody>
<div class="modal-footer">
<DButton
@class="btn-primary"
@action="dismiss"
@icon="check"
@id="dismiss-read-confirm"
@label="topics.bulk.dismiss"
/>
</div>