UX: Bookmark removal tweaks (#9635)

* Do not show confirmation modal if deleting bookmark from list unless the bookmark has a reminder
* Remove the deleted bookmark from the in-memory array for the user list so a full reload of the list is not needed and scrolling is maintained
This commit is contained in:
Martin Brennan 2020-05-05 14:56:04 +10:00 committed by GitHub
parent 9bff0882c3
commit 6aa9014509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -38,11 +38,23 @@ export default Controller.extend({
return loaded && contentLength === 0 && noResultsHelp;
},
_removeBookmarkFromList(bookmark) {
this.content.removeObject(bookmark);
},
@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 bookmark.destroy().then(() => this.loadItems());
return deleteBookmark();
}
});
},

View File

@ -1,6 +1,7 @@
import { acceptance } from "helpers/qunit-helpers";
import selectKit from "helpers/select-kit-helper";
import pretender from "helpers/create-pretender";
import userFixtures from "fixtures/user_fixtures";
acceptance("User's bookmarks", {
loggedIn: true,
@ -20,16 +21,25 @@ test("listing user bookmarks", async assert => {
assert.ok(find(".bookmark-list-item").length);
});
test("removing a bookmark", async assert => {
test("removing a bookmark with a reminder shows a confirmation", async assert => {
let listResponse = _.clone(userFixtures["/u/eviltrout/bookmarks.json"]);
listResponse.user_bookmark_list.bookmarks[0].reminder_at = "2028-01-01T08:00";
pretender.get("/u/eviltrout/bookmarks.json", () => [
200,
{ "Content-Type": "application/json" },
listResponse
]);
await visit("/u/eviltrout/activity/bookmarks");
const dropdown = selectKit(".bookmark-actions-dropdown");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.ok(exists(".bootbox.modal"));
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
await click(".bootbox.modal .btn-primary");
await click(".bootbox.modal a.btn-primary");
assert.not(exists(".bootbox.modal"));
listResponse.user_bookmark_list.bookmarks[0].reminder_at = null;
});
test("listing users bookmarks - no bookmarks", async assert => {
@ -48,3 +58,13 @@ test("listing users bookmarks - no bookmarks", async assert => {
assert.equal(find(".alert.alert-info").text(), "no bookmarks");
});
test("removing a bookmark with no reminder does not show a confirmation", async assert => {
await visit("/u/eviltrout/activity/bookmarks");
const dropdown = selectKit(".bookmark-actions-dropdown");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.not(exists(".bootbox.modal"), "it should not show the modal");
});