FIX: Show topic level bookmark with reminder modal (#9336)
* When using the topic-level bookmark button or shortcut, we now show the bookmark with reminder modal for consistency. * When hovering on a bookmark reminder notification where the bookmark has a name, show the name of the bookmark on hover.
This commit is contained in:
parent
7e42963590
commit
42c2678d8f
|
@ -339,26 +339,30 @@ const Post = RestModel.extend({
|
|||
toggleBookmarkWithReminder() {
|
||||
this.toggleProperty("bookmarked_with_reminder");
|
||||
if (this.bookmarked_with_reminder) {
|
||||
let controller = showModal("bookmark", {
|
||||
model: {
|
||||
postId: this.id
|
||||
},
|
||||
title: "post.bookmarks.create",
|
||||
modalClass: "bookmark-with-reminder"
|
||||
});
|
||||
controller.setProperties({
|
||||
onCloseWithoutSaving: () => {
|
||||
this.toggleProperty("bookmarked_with_reminder");
|
||||
this.appEvents.trigger("post-stream:refresh", { id: this.id });
|
||||
},
|
||||
afterSave: (reminderAtISO, reminderType) => {
|
||||
this.setProperties({
|
||||
"topic.bookmarked": true,
|
||||
bookmark_reminder_at: reminderAtISO,
|
||||
bookmark_reminder_type: reminderType
|
||||
});
|
||||
this.appEvents.trigger("post-stream:refresh", { id: this.id });
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
let controller = showModal("bookmark", {
|
||||
model: {
|
||||
postId: this.id
|
||||
},
|
||||
title: "post.bookmarks.create",
|
||||
modalClass: "bookmark-with-reminder"
|
||||
});
|
||||
controller.setProperties({
|
||||
onCloseWithoutSaving: () => {
|
||||
this.toggleProperty("bookmarked_with_reminder");
|
||||
this.appEvents.trigger("post-stream:refresh", { id: this.id });
|
||||
resolve();
|
||||
},
|
||||
afterSave: (reminderAtISO, reminderType) => {
|
||||
this.setProperties({
|
||||
"topic.bookmarked": true,
|
||||
bookmark_reminder_at: reminderAtISO,
|
||||
bookmark_reminder_type: reminderType
|
||||
});
|
||||
this.appEvents.trigger("post-stream:refresh", { id: this.id });
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.setProperties({
|
||||
|
|
|
@ -397,6 +397,16 @@ const Topic = RestModel.extend({
|
|||
}).then(() => this.set("archetype", "regular"));
|
||||
},
|
||||
|
||||
afterTopicBookmarked(firstPost) {
|
||||
if (firstPost) {
|
||||
firstPost.set("bookmarked", true);
|
||||
if (this.siteSettings.enable_bookmarks_with_reminders) {
|
||||
firstPost.set("bookmarked_with_reminder", true);
|
||||
}
|
||||
return [firstPost.id];
|
||||
}
|
||||
},
|
||||
|
||||
toggleBookmark() {
|
||||
if (this.bookmarking) {
|
||||
return Promise.resolve();
|
||||
|
@ -408,41 +418,48 @@ const Topic = RestModel.extend({
|
|||
const firstPost =
|
||||
posts && posts[0] && posts[0].get("post_number") === 1 && posts[0];
|
||||
const bookmark = !this.bookmarked;
|
||||
const path = bookmark ? "/bookmark" : "/remove_bookmarks";
|
||||
|
||||
const toggleBookmarkOnServer = () => {
|
||||
return ajax(`/t/${this.id}${path}`, { type: "PUT" })
|
||||
.then(() => {
|
||||
this.toggleProperty("bookmarked");
|
||||
if (bookmark && firstPost) {
|
||||
firstPost.set("bookmarked", true);
|
||||
if (this.siteSettings.enable_bookmarks_with_reminders) {
|
||||
firstPost.set("bookmarked_with_reminder", true);
|
||||
if (bookmark) {
|
||||
if (this.siteSettings.enable_bookmarks_with_reminders) {
|
||||
return firstPost.toggleBookmarkWithReminder().then(() => {
|
||||
this.set("bookmarking", false);
|
||||
return this.afterTopicBookmarked(firstPost);
|
||||
});
|
||||
} else {
|
||||
return ajax(`/t/${this.id}/bookmark`, { type: "PUT" })
|
||||
.then(() => {
|
||||
this.toggleProperty("bookmarked");
|
||||
return this.afterTopicBookmarked(firstPost);
|
||||
})
|
||||
.catch(popupAjaxError)
|
||||
.finally(() => this.set("bookmarking", false));
|
||||
}
|
||||
} else {
|
||||
return ajax(`/t/${this.id}/remove_bookmarks`, { type: "PUT" })
|
||||
.then(() => {
|
||||
this.toggleProperty("bookmarked");
|
||||
if (posts) {
|
||||
const updated = [];
|
||||
posts.forEach(post => {
|
||||
if (post.get("bookmarked")) {
|
||||
post.set("bookmarked", false);
|
||||
updated.push(post.id);
|
||||
}
|
||||
if (
|
||||
this.siteSettings.enable_bookmarks_with_reminders &&
|
||||
post.get("bookmarked_with_reminder")
|
||||
) {
|
||||
post.set("bookmarked_with_reminder", false);
|
||||
updated.push(post.id);
|
||||
}
|
||||
});
|
||||
return updated;
|
||||
}
|
||||
return [firstPost.id];
|
||||
}
|
||||
if (!bookmark && posts) {
|
||||
const updated = [];
|
||||
posts.forEach(post => {
|
||||
if (post.get("bookmarked")) {
|
||||
post.set("bookmarked", false);
|
||||
updated.push(post.id);
|
||||
}
|
||||
if (
|
||||
this.siteSettings.enable_bookmarks_with_reminders &&
|
||||
post.get("bookmarked_with_reminder")
|
||||
) {
|
||||
post.set("bookmarked_with_reminder", false);
|
||||
updated.push(post.id);
|
||||
}
|
||||
});
|
||||
return updated;
|
||||
}
|
||||
|
||||
return [];
|
||||
})
|
||||
.catch(popupAjaxError)
|
||||
.finally(() => this.set("bookmarking", false));
|
||||
})
|
||||
.catch(popupAjaxError)
|
||||
.finally(() => this.set("bookmarking", false));
|
||||
}
|
||||
};
|
||||
|
||||
const unbookmarkedPosts = [];
|
||||
|
|
|
@ -14,6 +14,19 @@ createWidgetFrom(
|
|||
description,
|
||||
username
|
||||
});
|
||||
},
|
||||
notificationTitle(notificationName, data) {
|
||||
if (notificationName) {
|
||||
if (data.bookmark_name) {
|
||||
return I18n.t(`notifications.titles.${notificationName}_with_name`, {
|
||||
name: data.bookmark_name
|
||||
});
|
||||
} else {
|
||||
return I18n.t(`notifications.titles.${notificationName}`);
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1880,6 +1880,7 @@ en:
|
|||
moved_post: "post moved"
|
||||
linked: "linked"
|
||||
bookmark_reminder: "bookmark reminder"
|
||||
bookmark_reminder_with_name: "bookmark reminder - %{name}"
|
||||
granted_badge: "badge granted"
|
||||
invited_to_topic: "invited to topic"
|
||||
group_mentioned: "group mentioned"
|
||||
|
|
Loading…
Reference in New Issue