mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 23:54:16 +08:00
DEV: Decouple the user status modal from current user's status (#18514)
This commit is contained in:
parent
140200ae83
commit
b06cc8a836
|
@ -6,6 +6,8 @@ import showModal from "discourse/lib/show-modal";
|
||||||
export default class UserMenuProfileTabContent extends Component {
|
export default class UserMenuProfileTabContent extends Component {
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
|
@service userStatus;
|
||||||
|
|
||||||
saving = false;
|
saving = false;
|
||||||
|
|
||||||
get showToggleAnonymousButton() {
|
get showToggleAnonymousButton() {
|
||||||
|
@ -59,6 +61,11 @@ export default class UserMenuProfileTabContent extends Component {
|
||||||
showModal("user-status", {
|
showModal("user-status", {
|
||||||
title: "user_status.set_custom_status",
|
title: "user_status.set_custom_status",
|
||||||
modalClass: "user-status",
|
modalClass: "user-status",
|
||||||
|
model: {
|
||||||
|
status: this.currentUser.status,
|
||||||
|
saveAction: (status) => this.userStatus.set(status),
|
||||||
|
deleteAction: () => this.userStatus.clear(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { inject as service } from "@ember/service";
|
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import ItsATrap from "@discourse/itsatrap";
|
import ItsATrap from "@discourse/itsatrap";
|
||||||
|
@ -11,17 +10,16 @@ import {
|
||||||
} from "discourse/lib/time-shortcut";
|
} from "discourse/lib/time-shortcut";
|
||||||
|
|
||||||
export default Controller.extend(ModalFunctionality, {
|
export default Controller.extend(ModalFunctionality, {
|
||||||
userStatusService: service("user-status"),
|
|
||||||
showDeleteButton: false,
|
showDeleteButton: false,
|
||||||
prefilledDateTime: null,
|
prefilledDateTime: null,
|
||||||
timeShortcuts: null,
|
timeShortcuts: null,
|
||||||
_itsatrap: null,
|
_itsatrap: null,
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
const currentStatus = { ...this.currentUser.status };
|
const currentStatus = { ...this.model.status };
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
status: currentStatus,
|
status: currentStatus,
|
||||||
showDeleteButton: !!this.currentUser.status,
|
showDeleteButton: !!this.model.status,
|
||||||
timeShortcuts: this._buildTimeShortcuts(),
|
timeShortcuts: this._buildTimeShortcuts(),
|
||||||
prefilledDateTime: currentStatus?.ends_at,
|
prefilledDateTime: currentStatus?.ends_at,
|
||||||
});
|
});
|
||||||
|
@ -54,8 +52,8 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
delete() {
|
delete() {
|
||||||
this.userStatusService
|
this.model
|
||||||
.clear()
|
.deleteAction()
|
||||||
.then(() => this.send("closeModal"))
|
.then(() => this.send("closeModal"))
|
||||||
.catch((e) => this._handleError(e));
|
.catch((e) => this._handleError(e));
|
||||||
},
|
},
|
||||||
|
@ -72,11 +70,10 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
emoji: this.status.emoji,
|
emoji: this.status.emoji,
|
||||||
ends_at: this.status.endsAt?.toISOString(),
|
ends_at: this.status.endsAt?.toISOString(),
|
||||||
};
|
};
|
||||||
this.userStatusService
|
|
||||||
.set(newStatus)
|
this.model
|
||||||
.then(() => {
|
.saveAction(newStatus)
|
||||||
this.send("closeModal");
|
.then(() => this.send("closeModal"))
|
||||||
})
|
|
||||||
.catch((e) => this._handleError(e));
|
.catch((e) => this._handleError(e));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ createWidgetFrom(QuickAccessItem, "logout-item", {
|
||||||
|
|
||||||
createWidgetFrom(QuickAccessItem, "user-status-item", {
|
createWidgetFrom(QuickAccessItem, "user-status-item", {
|
||||||
tagName: "li.user-status",
|
tagName: "li.user-status",
|
||||||
|
services: ["userStatus"],
|
||||||
|
|
||||||
html() {
|
html() {
|
||||||
const status = this.currentUser.status;
|
const status = this.currentUser.status;
|
||||||
|
@ -41,6 +42,11 @@ createWidgetFrom(QuickAccessItem, "user-status-item", {
|
||||||
showModal("user-status", {
|
showModal("user-status", {
|
||||||
title: "user_status.set_custom_status",
|
title: "user_status.set_custom_status",
|
||||||
modalClass: "user-status",
|
modalClass: "user-status",
|
||||||
|
model: {
|
||||||
|
status: this.currentUser.status,
|
||||||
|
saveAction: (status) => this.userStatus.set(status),
|
||||||
|
deleteAction: () => this.userStatus.clear(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user