DEV: Review fixes for bookmark-list (#10642)

Make removeBookmark return a promise and do not use setProperties for no reason.

More context at https://review.discourse.org/t/fix-add-bookmark-list-component-10451/14450/3
This commit is contained in:
Martin Brennan 2020-09-10 15:01:53 +10:00 committed by GitHub
parent 521782fc9c
commit 40d5739a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 13 deletions

View File

@ -1,4 +1,5 @@
import Component from "@ember/component";
import { Promise } from "rsvp";
import I18n from "I18n";
import { action } from "@ember/object";
import showModal from "discourse/lib/show-modal";
@ -13,18 +14,28 @@ export default Component.extend({
@action
removeBookmark(bookmark) {
const deleteBookmark = () => {
return bookmark
.destroy()
.then(() => this._removeBookmarkFromList(bookmark));
};
if (!bookmark.reminder_at) {
return deleteBookmark();
}
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), (result) => {
if (result) {
return new Promise((resolve, reject) => {
const deleteBookmark = () => {
bookmark
.destroy()
.then(() => {
this._removeBookmarkFromList(bookmark);
resolve(true);
})
.catch((error) => {
reject(error);
});
};
if (!bookmark.reminder_at) {
return deleteBookmark();
}
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), (result) => {
if (result) {
deleteBookmark();
} else {
resolve(false);
}
});
});
},
@ -50,9 +61,7 @@ export default Component.extend({
title: "post.bookmarks.edit",
modalClass: "bookmark-with-reminder",
});
controller.setProperties({
afterSave: () => this.reload(),
});
controller.set("afterSave", () => this.reload());
},
_removeBookmarkFromList(bookmark) {