UX: Bookmark removal tweaks (#9635)

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
diff --git a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
index a24269d..0f44eee 100644
--- a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
+++ b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks.js
@@ -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();
       }
     });
   },
diff --git a/test/javascripts/acceptance/user-bookmarks-test.js b/test/javascripts/acceptance/user-bookmarks-test.js
index 3a27681..51dead8 100644
--- a/test/javascripts/acceptance/user-bookmarks-test.js
+++ b/test/javascripts/acceptance/user-bookmarks-test.js
@@ -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");
+});

GitHub sha: 6aa90145

This commit appears in #9635 which was merged by martin.