FEATURE: Optionally delete bookmark when reminder sent (#9637)

FEATURE: Optionally delete bookmark when reminder sent (#9637)

We now show an options gear icon next to the bookmark name.

When expanded we show the “delete bookmark when reminder sent” option. The value of this checkbox is saved in local storage for the user.

If this is ticked, when a reminder is sent for the bookmark the bookmark itself is deleted. This is so people can use the reminder functionality by itself.

Also remove the blue alert reminder section from the “Edit Bookmark” modal as it just added clutter, because the user can already see they had a reminder set:

Adds a default false boolean column delete_when_reminder_sent to bookmarks.

diff --git a/app/assets/javascripts/discourse/app/controllers/bookmark.js b/app/assets/javascripts/discourse/app/controllers/bookmark.js
index 992c322..7d86ed2 100644
--- a/app/assets/javascripts/discourse/app/controllers/bookmark.js
+++ b/app/assets/javascripts/discourse/app/controllers/bookmark.js
@@ -1,4 +1,5 @@
 import { and } from "@ember/object/computed";
+import { next } from "@ember/runloop";
 import { action } from "@ember/object";
 import { isPresent } from "@ember/utils";
 import Controller from "@ember/controller";
@@ -59,6 +60,8 @@ export default Controller.extend(ModalFunctionality, {
   lastCustomReminderTime: null,
   mouseTrap: null,
   userTimezone: null,
+  showOptions: false,
+  options: null,
 
   onShow() {
     this.setProperties({
@@ -70,9 +73,13 @@ export default Controller.extend(ModalFunctionality, {
       customReminderTime: this._defaultCustomReminderTime(),
       lastCustomReminderDate: null,
       lastCustomReminderTime: null,
-      userTimezone: this.currentUser.resolvedTimezone()
+      userTimezone: this.currentUser.resolvedTimezone(),
+      showOptions: false,
+      options: {},
+      model: this.model || {}
     });
 
+    this._loadBookmarkOptions();
     this._bindKeyboardShortcuts();
     this._loadLastUsedCustomReminderDatetime();
 
@@ -124,6 +131,21 @@ export default Controller.extend(ModalFunctionality, {
     return isPresent(this.model) && isPresent(this.model.reminderAt);
   },
 
+  _loadBookmarkOptions() {
+    this.set(
+      "options.deleteWhenReminderSent",
+      this.model.deleteWhenReminderSent ||
+        localStorage.bookmarkOptionsDeleteWhenReminderSent === "true"
+    );
+
+    // we want to make sure the options panel opens so the user
+    // knows they have set these options previously. run next otherwise
+    // the modal is not visible when it tries to slide down the options
+    if (this.options.deleteWhenReminderSent) {
+      next(() => this.toggleOptionsPanel());
+    }
+  },
+
   _loadLastUsedCustomReminderDatetime() {
     let lastTime = localStorage.lastCustomBookmarkReminderTime;
     let lastDate = localStorage.lastCustomBookmarkReminderDate;
@@ -268,6 +290,8 @@ export default Controller.extend(ModalFunctionality, {
       localStorage.lastCustomBookmarkReminderDate = this.customReminderDate;
     }
 
+    localStorage.bookmarkOptionsDeleteWhenReminderSent = this.options.deleteWhenReminderSent;
+
     let reminderType;
     if (this.selectedReminderType === REMINDER_TYPES.NONE) {
       reminderType = null;
@@ -282,7 +306,8 @@ export default Controller.extend(ModalFunctionality, {
       reminder_at: reminderAtISO,
       name: this.model.name,
       post_id: this.model.postId,
-      id: this.model.id
+      id: this.model.id,
+      delete_when_reminder_sent: this.options.deleteWhenReminderSent
     };
 
     if (this._editingExistingBookmark()) {
@@ -294,6 +319,7 @@ export default Controller.extend(ModalFunctionality, {
           this.afterSave({
             reminderAt: reminderAtISO,
             reminderType: this.selectedReminderType,
+            deleteWhenReminderSent: this.options.deleteWhenReminderSent,
             id: this.model.id,
             name: this.model.name
           });
@@ -305,6 +331,7 @@ export default Controller.extend(ModalFunctionality, {
           this.afterSave({
             reminderAt: reminderAtISO,
             reminderType: this.selectedReminderType,
+            deleteWhenReminderSent: this.options.deleteWhenReminderSent,
             id: response.id,
             name: this.model.name
           });
@@ -421,6 +448,16 @@ export default Controller.extend(ModalFunctionality, {
   },
 
   @action
+  toggleOptionsPanel() {
+    if (this.showOptions) {
+      $(".bookmark-options-panel").slideUp("fast");
+    } else {
+      $(".bookmark-options-panel").slideDown("fast");
+    }
+    this.toggleProperty("showOptions");
+  },
+
+  @action
   saveAndClose() {
     if (this._saving || this._deleting) {
       return;
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index e7cf602..e0565b4 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -316,6 +316,7 @@ const Post = RestModel.extend({
           postId: this.id,
           id: this.bookmark_id,
           reminderAt: this.bookmark_reminder_at,
+          deleteWhenReminderSent: this.bookmark_delete_when_reminder_sent,
           name: this.bookmark_name
         },
         title: this.bookmark_id
@@ -334,6 +335,8 @@ const Post = RestModel.extend({
             bookmarked: true,
             bookmark_reminder_at: savedData.reminderAt,
             bookmark_reminder_type: savedData.reminderType,
+            bookmark_delete_when_reminder_sent:
+              savedData.deleteWhenReminderSent,
             bookmark_name: savedData.name,
             bookmark_id: savedData.id
           });
diff --git a/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs b/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs
index 2cac81e..b69713e 100644
--- a/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs
+++ b/app/assets/javascripts/discourse/app/templates/modal/bookmark.hbs
@@ -8,8 +8,16 @@
       </div>
     {{/if}}
 
-    <div class="control-group">
+    <div class="control-group bookmark-name-wrap">
       {{input id="bookmark-name" value=model.name name="name" class="bookmark-name" placeholder=(i18n "post.bookmarks.name_placeholder")}}
+      {{d-button icon="gear" action=(action "toggleOptionsPanel") class="bookmark-options-button"}}
+    </div>
+
+    <div class="bookmark-options-panel">
+      <label for="delete_when_reminder_sent">
+        {{i18n "bookmarks.delete_when_reminder_sent"}}
+        {{input id="delete_when_reminder_sent" type="checkbox" checked=options.deleteWhenReminderSent}}
+      </label>
     </div>
 
     {{#if showExistingReminderAt }}
diff --git a/app/assets/stylesheets/common/components/bookmark-modal.scss b/app/assets/stylesheets/common/components/bookmark-modal.scss
index 45ad12f..b870ec0 100644
--- a/app/assets/stylesheets/common/components/bookmark-modal.scss
+++ b/app/assets/stylesheets/common/components/bookmark-modal.scss
@@ -62,4 +62,24 @@
       flex: 1 1 auto;
     }
   }
+
+  .bookmark-name-wrap {
+    display: inline-flex;
+    width: 100%;
+    align-items: end;
+  }
+
+  .bookmark-options-button {
+    margin-left: 0.5em;
+    background: transparent;
+  }
+
+  .bookmark-options-panel {
+    margin-bottom: 18px;
+    display: none;
+
+    input[type="checkbox"] {
+      margin-right: 0.85em;
+    }
+  }
 }
diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb
index f7fed51..001e75c 100644
--- a/app/controllers/bookmarks_controller.rb
+++ b/app/controllers/bookmarks_controller.rb
@@ -11,7 +11,10 @@ class BookmarksController < ApplicationController
       post_id: params[:post_id],
       name: params[:name],
       reminder_type: params[:reminder_type],
-      reminder_at: params[:reminder_at]
+      reminder_at: params[:reminder_at],
+      options: {
+        delete_when_reminder_sent: params[:delete_when_reminder_sent]
+      }
     )
 
     if bookmark_manager.errors.empty?
@@ -35,7 +38,10 @@ class BookmarksController < ApplicationController
       bookmark_id: params[:id],
       name: params[:name],
       reminder_type: params[:reminder_type],
-      reminder_at: params[:reminder_at]
+      reminder_at: params[:reminder_at],
+      options: {
+        delete_when_reminder_sent: params[:delete_when_reminder_sent]
+      }
     )
 
     if bookmark_manager.errors.empty?
diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb
index 3cfae4f..3125f8f 100644
--- a/app/models/bookmark.rb
+++ b/app/models/bookmark.rb
@@ -79,17 +79,18 @@ end
 #
 # Table name: bookmarks
 #

[... diff too long, it was truncated ...]

GitHub sha: 6fb0f36c

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