mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Pop revise modal on post edited notification (#6287)
* Add revision number to notification url * Pop modal on route change * Add semicolon * Ensure modal pops even when navigating within a topic * Ensure modal pops when visiting from other page * Fix eslint errors * Fix prettier errors * Add callback for notification item click * Remove stray revisionUrl function * Rename to afterRouteComplete
This commit is contained in:
@@ -98,6 +98,16 @@ export default Ember.Controller.extend(BufferedContent, {
|
||||
|
||||
init() {
|
||||
this._super();
|
||||
this.appEvents.on("post:show-revision", (postNumber, revision) => {
|
||||
const post = this.model.get("postStream").postForPostNumber(postNumber);
|
||||
if (!post) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ember.run.scheduleOnce("afterRender", () => {
|
||||
this.send("showHistory", post, revision);
|
||||
});
|
||||
});
|
||||
this.setProperties({
|
||||
selectedPostIds: [],
|
||||
quoteState: new QuoteState()
|
||||
|
||||
@@ -242,6 +242,10 @@ const DiscourseURL = Ember.Object.extend({
|
||||
|
||||
path = rewritePath(path);
|
||||
|
||||
if (typeof opts.afterRouteComplete === "function") {
|
||||
Ember.run.schedule("afterRender", opts.afterRouteComplete);
|
||||
}
|
||||
|
||||
if (this.navigatedToPost(oldPath, path, opts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -711,6 +711,16 @@ export default RestModel.extend({
|
||||
return resolved;
|
||||
},
|
||||
|
||||
postForPostNumber(postNumber) {
|
||||
if (!this.get("hasPosts")) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.get("posts").find(p => {
|
||||
return p.get("post_number") === postNumber;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Returns the closest post given a postNumber that may not exist in the stream.
|
||||
For example, if the user asks for a post that's deleted or otherwise outside the range.
|
||||
|
||||
@@ -91,11 +91,11 @@ const TopicRoute = Discourse.Route.extend({
|
||||
this.controllerFor("invite").reset();
|
||||
},
|
||||
|
||||
showHistory(model) {
|
||||
showHistory(model, revision) {
|
||||
showModal("history", { model });
|
||||
const historyController = this.controllerFor("history");
|
||||
|
||||
historyController.refresh(model.get("id"), "latest");
|
||||
historyController.refresh(model.get("id"), revision || "latest");
|
||||
historyController.set("post", model);
|
||||
historyController.set("topicController", this.controllerFor("topic"));
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ createWidget("notification-item", {
|
||||
}
|
||||
|
||||
const topicId = attrs.topic_id;
|
||||
|
||||
if (topicId) {
|
||||
return postUrl(attrs.slug, topicId, attrs.post_number);
|
||||
}
|
||||
@@ -152,6 +153,18 @@ createWidget("notification-item", {
|
||||
e.preventDefault();
|
||||
|
||||
this.sendWidgetEvent("linkClicked");
|
||||
DiscourseURL.routeTo(this.url());
|
||||
DiscourseURL.routeTo(this.url(), {
|
||||
afterRouteComplete: () => {
|
||||
if (!this.attrs.data.revision_number) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.appEvents.trigger(
|
||||
"post:show-revision",
|
||||
this.attrs.post_number,
|
||||
this.attrs.data.revision_number
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user