UX: adds visual feedback when changing topic notifications level (#9831)

This commit is contained in:
Joffrey JAFFEUX 2020-05-19 13:27:57 +02:00 committed by GitHub
parent 05ca0c908f
commit 7c3663ff73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 7 deletions

View File

@ -61,12 +61,14 @@ const TopicDetails = RestModel.extend({
}
},
updateNotifications(v) {
this.set("notification_level", v);
this.set("notifications_reason_id", null);
return ajax("/t/" + this.get("topic.id") + "/notifications", {
updateNotifications(level) {
this.setProperties({
notification_level: level,
notifications_reason_id: null
});
return ajax(`/t/${this.get("topic.id")}/notifications`, {
type: "POST",
data: { notification_level: v }
data: { notification_level: level }
});
},

View File

@ -1,20 +1,38 @@
import Component from "@ember/component";
import { action } from "@ember/object";
import { action, computed } from "@ember/object";
import { later, cancel } from "@ember/runloop";
export default Component.extend({
layoutName: "select-kit/templates/components/topic-notifications-button",
classNames: ["topic-notifications-button"],
classNameBindings: ["isLoading"],
appendReason: true,
showFullTitle: true,
placement: "bottom-start",
notificationLevel: null,
topic: null,
showCaret: true,
isLoading: false,
icon: computed("isLoading", function() {
return this.isLoading ? "spinner" : null;
}),
willDestroyElement() {
this._super(...arguments);
this._endLoadingHandler && cancel(this._endLoadingHandler);
},
@action
changeTopicNotificationLevel(levelId) {
if (levelId !== this.notificationLevel) {
this.topic.details.updateNotifications(levelId);
this.set("isLoading", true);
this.topic.details.updateNotifications(levelId).finally(() => {
this._endLoadingHandler = later(
() => this.set("isLoading", false),
250
);
});
}
}
});

View File

@ -5,6 +5,7 @@
topic=topic
onChange=(action "changeTopicNotificationLevel")
options=(hash
icon=icon
showFullTitle=showFullTitle
placement=placement
preventsClickPropagation=true
@ -19,6 +20,7 @@
topic=topic
onChange=(action "changeTopicNotificationLevel")
options=(hash
icon=icon
showFullTitle=showFullTitle
placement=placement
preventsClickPropagation=true

View File

@ -1026,6 +1026,14 @@ a.mention-group {
margin-top: 0;
}
.topic-notifications-button.is-loading {
pointer-events: none;
user-select: none;
.topic-notifications-options {
opacity: 0.5;
}
}
.pinned-button,
.topic-notifications-button {
margin: 1em 0;

View File

@ -63,6 +63,11 @@
flex-direction: row;
min-height: 30px;
.d-icon-spinner {
-webkit-animation: rotate-forever 1s infinite linear;
animation: rotate-forever 1s infinite linear;
}
.selected-name {
text-align: left;
flex: 0 1 auto;