Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Allow acting on all bookmarks in topic footer buttons (#39063)

Sam2ec93c6f5639
diff --git a/app/assets/stylesheets/common/components/bookmark-menu.scss b/app/assets/stylesheets/common/components/bookmark-menu.scss
index 7b6c3791e93..db29a222a58 100644
--- a/app/assets/stylesheets/common/components/bookmark-menu.scss
+++ b/app/assets/stylesheets/common/components/bookmark-menu.scss
@@ -1,3 +1,5 @@
+@use "lib/viewport";
+
.bookmark-menu-content {
.bookmark-menu__title {
background: var(--tertiary-low);
@@ -23,3 +25,70 @@
}
}
}
+
+.topic-bookmarks-menu-content {
+ @include viewport.from(sm) {
+ max-height: 60vh;
+ }
+
+ .--jump {
+ .btn {
+ .discourse-no-touch & {
+ &:hover,
+ &:focus-visible {
+ background: var(--d-hover);
+ }
+ }
+ }
+ }
+
+ .--has-name {
+ .btn {
+ height: auto;
+ min-height: 2.2em;
+ padding: var(--space-1);
+ }
+
+ .d-icon {
+ align-self: flex-start;
+ padding-top: var(--space-1);
+ }
+ }
+
+ .bookmark-menu__row-texts {
+ line-height: var(--line-height-medium);
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ }
+
+ .bookmark-menu__row-description {
+ font-size: var(--font-down-1);
+ color: var(--primary-medium);
+ white-space: normal;
+ overflow-wrap: anywhere;
+ text-align: left;
+ max-width: 35ch;
+ }
+
+ .bookmark-menu__section-title {
+ display: flex;
+ align-items: center;
+ font-weight: 700;
+ font-size: var(--font-down-1);
+ color: var(--primary-medium);
+ gap: var(--d-sidebar-section-link-prefix-margin-right);
+ padding-inline: var(--d-sidebar-row-horizontal-padding);
+ padding-block: 0.35em;
+
+ .d-icon {
+ width: var(--d-sidebar-section-link-prefix-width);
+ }
+
+ span {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+ }
+}
diff --git a/app/serializers/topic_view_bookmark_serializer.rb b/app/serializers/topic_view_bookmark_serializer.rb
index 60faf680941..1bc1b2dc4f8 100644
--- a/app/serializers/topic_view_bookmark_serializer.rb
+++ b/app/serializers/topic_view_bookmark_serializer.rb
@@ -1,5 +1,11 @@
# frozen_string_literal: true
class TopicViewBookmarkSerializer < ApplicationSerializer
- attributes :id, :bookmarkable_id, :bookmarkable_type, :reminder_at, :name, :auto_delete_preference
+ attributes :id,
+ :bookmarkable_id,
+ :bookmarkable_type,
+ :reminder_at,
+ :name,
+ :auto_delete_preference,
+ :post_number
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 5ad5fde2e72..62a04d1c47a 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -610,8 +610,10 @@ en:
bookmarked:
title: "Bookmark"
- edit_bookmark: "Edit Bookmark"
- clear_bookmarks: "Clear Bookmarks"
+ edit_bookmark:
+ one: "Edit bookmark"
+ other: "Edit bookmarks"
+ delete_bookmarks: "Delete all bookmarks"
help:
bookmark: "Click to bookmark this topic"
edit_bookmark: "Click to edit the bookmark on a post in this topic"
@@ -631,12 +633,18 @@ en:
clear_reminder: "Clear reminder"
edit: "Edit bookmark"
not_bookmarked: "bookmark this post"
+ topic_bookmark: "Topic"
+ post_bookmark: "Post #%{post_number}"
+ jump_to_post: "Jump to #%{post_number}"
+ bookmark_topic: "Bookmark topic"
+ edit_topic_bookmark: "Edit topic bookmark"
+ delete_topic_bookmark: "Delete topic bookmark"
remove_reminder_keep_bookmark: "Remove reminder and keep bookmark"
created_with_reminder: "You've bookmarked this post with a reminder %{date}. %{name}"
created_with_reminder_generic: "You've bookmarked this with a reminder %{date}. %{name}"
delete: "Delete Bookmark"
confirm_delete: "Are you sure you want to delete this bookmark? The reminder will also be deleted."
- confirm_clear: "Are you sure you want to clear all your bookmarks from this topic?"
+ confirm_clear: "Are you sure you want to delete all your bookmarks from this topic?"
save: "Save"
no_timezone: 'You have not set a timezone yet. You will not be able to set reminders. Set one up <a href="%{basePath}/my/preferences/profile">in your profile</a>.'
invalid_custom_datetime: "The date and time you provided is invalid, please try again."
diff --git a/frontend/discourse/app/components/bookmark-menu.gjs b/frontend/discourse/app/components/bookmark-menu.gjs
index 7baad93881e..1b7f52090d8 100644
--- a/frontend/discourse/app/components/bookmark-menu.gjs
+++ b/frontend/discourse/app/components/bookmark-menu.gjs
@@ -116,7 +116,7 @@ export default class BookmarkMenu extends Component {
}
if (this.existingBookmark) {
- return i18n("bookmarked.edit_bookmark");
+ return i18n("bookmarked.edit_bookmark", { count: 1 });
} else {
return i18n("bookmarked.title");
}
diff --git a/frontend/discourse/app/components/d-button.gjs b/frontend/discourse/app/components/d-button.gjs
index f53da26d849..f4a2bfacf3a 100644
--- a/frontend/discourse/app/components/d-button.gjs
+++ b/frontend/discourse/app/components/d-button.gjs
@@ -264,6 +264,8 @@ export default class DButton extends Component {
&hellip;
{{~/if~}}
</span>
+ {{~else if (has-block)~}}
+ {{! Block content provides the label, no spacer needed }}
{{~else if (or @icon @isLoading)~}}
<span aria-hidden="true">
&#8203;
diff --git a/frontend/discourse/app/components/topic-bookmarks-menu.gjs b/frontend/discourse/app/components/topic-bookmarks-menu.gjs
new file mode 100644
index 00000000000..669e48415d7
--- /dev/null
+++ b/frontend/discourse/app/components/topic-bookmarks-menu.gjs
@@ -0,0 +1,481 @@
+import Component from "@glimmer/component";
+import { fn } from "@ember/helper";
+import { action } from "@ember/object";
+import { getOwner } from "@ember/owner";
+import { service } from "@ember/service";
+import BookmarkMenu from "discourse/components/bookmark-menu";
+import DButton from "discourse/components/d-button";
+import DropdownMenu from "discourse/components/dropdown-menu";
+import BookmarkModal from "discourse/components/modal/bookmark";
+import DMenu from "discourse/float-kit/components/d-menu";
+import concatClass from "discourse/helpers/concat-class";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { BookmarkFormData } from "discourse/lib/bookmark-form-data";
+import TopicBookmarkManager from "discourse/lib/topic-bookmark-manager";
+import DiscourseURL from "discourse/lib/url";
+import {
+ NO_REMINDER_ICON,
+ NOT_BOOKMARKED,
+ WITH_REMINDER_ICON,
+} from "discourse/models/bookmark";
+import { i18n } from "discourse-i18n";
+
+export default class TopicBookmarksMenu extends Component {
+ @service modal;
+ @service dialog;
+ @service bookmarkApi;
+ @service toasts;
+ @service currentUser;
+
+ get topic() {
+ return this.args.topic;
+ }
+
+ get allBookmarks() {
+ return this.topic.bookmarks || [];
+ }
+
+ get postBookmarks() {
+ return this.allBookmarks
+ .filter((b) => b.bookmarkable_type === "Post")
+ .sort((a, b) => (a.post_number || 0) - (b.post_number || 0));
+ }
+
+ get topicBookmark() {
+ return this.allBookmarks.find((b) => b.bookmarkable_type === "Topic");
+ }
+
+ get hasPostBookmarks() {
+ return this.postBookmarks.length > 0;
+ }
+
+ get useGroupedDropdown() {
+ return this.hasPostBookmarks;
+ }
+
+ get singlePostBookmark() {
+ if (
+ this.allBookmarks.length === 1 &&
+ this.allBookmarks[0].bookmarkable_type === "Post"
+ ) {
+ return this.allBookmarks[0];
+ }
+ return null;
+ }
+
+ get isMultipleBookmarks() {
+ return this.allBookmarks.length > 1;
+ }
+
+ get topicBookmarkManager() {
+ return new TopicBookmarkManager(getOwner(this), this.topic);
+ }
+
+ get buttonLabel() {
+ if (!this.args.showLabel) {
+ return;
+ }
+
+ if (this.allBookmarks.length >= 1) {
+ return i18n("bookmarked.edit_bookmark", {
+ count: this.allBookmarks.length,
+ });
+ } else {
+ return i18n("bookmarked.title");
+ }
+ }
+
+ get buttonIcon() {
+ if (this.topicBookmark?.reminder_at) {
+ return WITH_REMINDER_ICON;
+ } else if (this.topicBookmark) {
+ return NO_REMINDER_ICON;
+ } else {
+ return NOT_BOOKMARKED;
+ }
+ }
+
+ get buttonTitle() {
+ if (this.allBookmarks.length === 0) {
+ return i18n("bookmarks.not_bookmarked");
+ }
+
+ if (this.allBookmarks.length === 1) {
+ const bm = this.allBookmarks[0];
+ if (bm.reminder_at) {
+ return i18n("bookmarks.created_with_reminder_generic", {
+ date: new BookmarkFormData(bm).formattedReminder(this.#timezone),
+ name: bm.name || "",
+ });
+ }
+ return i18n("bookmarks.created_generic", { name: bm.name || "" });
+ }
+
+ return i18n("bookmarked.edit_bookmark", {
+ count: this.allBookmarks.length,
+ });
+ }
+
+ get buttonClasses() {
+ const classes = ["bookmark", "widget-button", "bookmark-menu__trigger"];
+
+ if (!this.args.showLabel) {
+ classes.push("btn-icon", "no-text");
+ } else {
+ classes.push("btn-icon-text");
+ }
+
+ if (this.args.buttonClasses) {
+ classes.push(this.args.buttonClasses);
+ }
+
+ if (this.allBookmarks.length > 0) {
+ classes.push("bookmarked");
+ if (this.allBookmarks.some((b) => b.reminder_at)) {
+ classes.push("with-reminder");
+ }
+ }
+
+ return classes.join(" ");
+ }
+
+ @action
+ onRegisterApi(api) {
+ this.dMenu = api;
+ }
+
+ @action
+ async onJumpToPost(bookmark) {
+ await this.dMenu.close();
+ DiscourseURL.routeTo(this.topic.urlForPostNumber(bookmark.post_number));
+ }
+
+ @action
+ async onBookmarkTopic() {
+ await this.dMenu.close();
+
+ try {
+ await this.topicBookmarkManager.create();
+ this.toasts.success({
+ duration: "short",
+ data: { message: i18n("bookmarks.bookmarked_success") },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ }
+ }
+
+ @action
+ async onEditTopicBookmark() {
+ await this.dMenu.close();
+
+ const bookmark = this.topicBookmark;
+ const formData = new BookmarkFormData(bookmark);
+ try {
+ await this.modal.show(BookmarkModal, {
+ model: {
+ bookmark: formData,
+ afterSave: (savedData) => {
+ this.#syncBookmark(savedData.saveData);
+ this.topic.set("bookmarked", true);
+ this.topic.incrementProperty("bookmarksWereChanged");
+ this.topic.appEvents?.trigger(
+ "bookmarks:changed",
+ savedData.saveData,
+ { target: "topic", targetId: bookmark.bookmarkable_id }
+ );
+ },
+ afterDelete: (response, bookmarkId) => {
+ this.topic.removeBookmark(bookmarkId);
+ },
+ },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ }
+ }
+
+ @action
+ async onEditPostBookmark(bookmark) {
+ await this.dMenu.close();
+
+ const formData = new BookmarkFormData(bookmark);
+ try {
+ await this.modal.show(BookmarkModal, {
+ model: {
+ bookmark: formData,
+ afterSave: (savedData) => {
+ this.#syncBookmark(savedData.saveData);
+ this.topic.set("bookmarked", true);
+ this.topic.incrementProperty("bookmarksWereChanged");
+
+ const post = this.topic.postStream?.findLoadedPost(
+ bookmark.bookmarkable_id
+ );
+ if (post) {
+ post.createBookmark(savedData.saveData);
+ }
+ },
+ afterDelete: (response, bookmarkId) => {
+ this.#removeBookmark(bookmark, bookmarkId, response);
+ },
+ },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ }
+ }
+
+ @action
+ async onRemoveBookmark(bookmark) {
+ try {
+ const response = await this.bookmarkApi.delete(bookmark.id);
+ this.#removeBookmark(bookmark, bookmark.id, response);
+ this.toasts.success({
+ duration: "short",
+ data: {
+ icon: "trash-can",
+ message: i18n("bookmarks.deleted_bookmark_success"),
+ },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ await this.dMenu.close();
+ }
+ }
+
+ @action
+ async onRemoveTopicBookmark() {
+ try {
+ const bookmark = this.topicBookmark;
+ const response = await this.bookmarkApi.delete(bookmark.id);
+ this.topic.removeBookmark(bookmark.id);
+ if (response) {
+ this.topic.appEvents?.trigger("bookmarks:changed", null, {
+ target: "topic",
+ targetId: bookmark.bookmarkable_id,
+ });
+ }
+ this.toasts.success({
+ duration: "short",
+ data: {
+ icon: "trash-can",
+ message: i18n("bookmarks.deleted_bookmark_success"),
+ },
+ });
+ } catch (error) {
+ popupAjaxError(error);
+ } finally {
+ await this.dMenu.close();
+ }
+ }
+
+ @action
+ async onClearAllBookmarks() {
+ await this.dMenu.close();
+
+ this.dialog.yesNoConfirm({
+ message: i18n("bookmarks.confirm_clear"),
+ didConfirm: () => {
+ return this.topic
+ .deleteBookmarks()
+ .then(() => this.topic.clearBookmarks())
+ .catch(popupAjaxError);
+ },
+ });
+ }
+
+ #syncBookmark(data) {
+ const existing = this.topic.bookmarks.find((b) => b.id === data.id);
+ if (existing) {
+ existing.setProperties({
+ reminder_at: data.reminder_at,
+ name: data.name,
+ auto_delete_preference: data.auto_delete_preference,
+ });
+ }
+ this.topic.incrementProperty("bookmarksWereChanged");
+ }
+
+ #removeBookmark(bookmark, bookmarkId, response) {
+ if (bookmark.bookmarkable_type === "Post") {
+ const post = this.topic.postStream?.findLoadedPost(
+ bookmark.bookmarkable_id
+ );
+ if (post) {
+ post.deleteBookmark(response?.topic_bookmarked);
+ }
+ }
+ this.topic.removeBookmark(bookmarkId);
+ }
+
+ get #timezone() {
+ return this.currentUser?.user_option?.timezone || moment.tz.guess();
+ }
+
+ <template>
+ {{#if this.useGroupedDropdown}}
+ <DMenu
+ ...attributes
+ @identifier="topic-bookmarks-menu"
+ class={{this.buttonClasses}}
+ @title={{this.buttonTitle}}
+ @label={{this.buttonLabel}}
+ @icon={{this.buttonIcon}}
+ @onRegisterApi={{this.onRegisterApi}}
+ @modalForMobile={{true}}
+ @arrow={{false}}
+ >
+ <:content>
+ <DropdownMenu as |dropdown|>
+ {{! Post bookmark jump links }}
+ {{#each this.postBookmarks as |bookmark|}}
+ <dropdown.item
+ class={{concatClass
+ "bookmark-menu__row --jump"
+ (if bookmark.name "--has-name")
+ }}
+ data-menu-option-id="jump"
+ >
+ <DButton
+ @icon="bookmark"
+ @translatedAriaLabel={{i18n
+ "bookmarks.jump_to_post"
+ post_number=bookmark.post_number
+ }}
+ @action={{fn this.onJumpToPost bookmark}}
+ class="bookmark-menu__row-btn btn-transparent"
+ >
+ <span class="bookmark-menu__row-texts">
+ <span class="bookmark-menu__row-label">
+ {{i18n
+ "bookmarks.jump_to_post"
+ post_number=bookmark.post_number
+ }}
+ </span>
+ {{#if bookmark.name}}
+ <span class="bookmark-menu__row-description">
+ {{bookmark.name}}
+ </span>
+ {{/if}}
+ </span>
+ </DButton>
+ </dropdown.item>
+ {{/each}}
+
+ {{#if this.singlePostBookmark}}
+ {{! Single post bookmark: edit + delete }}
+ <dropdown.item
+ class="bookmark-menu__row -edit"
+ data-menu-option-id="edit"
+ >
+ <DButton
+ @icon="pencil"
+ @label="edit"
+ @action={{fn this.onEditPostBookmark this.singlePostBookmark}}
+ class="bookmark-menu__row-btn btn-transparent"
+ />
+ </dropdown.item>
+ <dropdown.item
+ class="bookmark-menu__row --remove"
+ data-menu-option-id="delete"
+ >
+ <DButton
+ @icon="trash-can"
+ @label="delete"
+ @action={{fn this.onRemoveBookmark this.singlePostBookmark}}
+ class="bookmark-menu__row-btn --danger"
+ />
+ </dropdown.item>
+ <dropdown.divider />
+ <dropdown.item
+ class="bookmark-menu__row --bookmark-topic"
+ data-menu-option-id="bookmark-topic"
+ >
+ <DButton
+ @icon="bookmark"
+ @label="bookmarks.bookmark_topic"
+ @action={{this.onBookmarkTopic}}
+ class="bookmark-menu__row-btn btn-transparent"
+ />
+ </dropdown.item>
+ {{else if this.isMultipleBookmarks}}
+ {{! Multiple bookmarks: topic bookmark actions + delete all }}
+ {{#if this.topicBookmark}}
+ <dropdown.divider />
+ <dropdown.item
+ class={{concatClass
+ "bookmark-menu__row -edit"
+ (if this.topicBookmark.name "--has-name")
+ }}
+ data-menu-option-id="edit-topic-bookmark"
+ >
+ <DButton
+ @icon="pencil"
+ @action={{this.onEditTopicBookmark}}
+ class="bookmark-menu__row-btn btn-transparent"
+ >
+ <span class="bookmark-menu__row-texts">
+ <span class="bookmark-menu__row-label">
+ {{i18n "bookmarks.edit_topic_bookmark"}}
+ </span>
+ {{#if this.topicBookmark.name}}
+ <span class="bookmark-menu__row-description">
+ {{this.topicBookmark.name}}
+ </span>
+ {{/if}}
+ </span>
+ </DButton>
+ </dropdown.item>
+ <dropdown.item
+ class="bookmark-menu__row --remove"
+ data-menu-option-id="delete-topic-bookmark"
+ >
+ <DButton
+ @icon="trash-can"
+ @action={{this.onRemoveTopicBookmark}}
+ @label="bookmarks.delete_topic_bookmark"
+ class="bookmark-menu__row-btn --danger"
+ />
+ </dropdown.item>
+ {{else}}
+ <dropdown.divider />
+ <dropdown.item
+ class="bookmark-menu__row --bookmark-topic"
+ data-menu-option-id="bookmark-topic"
+ >
+ <DButton
+ @icon="bookmark"
+ @label="bookmarks.bookmark_topic"
+ @action={{this.onBookmarkTopic}}
+ class="bookmark-menu__row-btn btn-transparent"
+ />
+ </dropdown.item>
+ {{/if}}
+ <dropdown.divider />
+ <dropdown.item
+ class="bookmark-menu__row --remove"
+ data-menu-option-id="clear-all"
+ >
+ <DButton
+ @icon="trash-can"
+ @label="bookmarked.delete_bookmarks"
+ @action={{this.onClearAllBookmarks}}
+ class="bookmark-menu__row-btn --danger"
+ />
+ </dropdown.item>
+ {{/if}}
+ </DropdownMenu>
+ </:content>
+ </DMenu>
+ {{else}}
+ <BookmarkMenu
+ @showLabel={{@showLabel}}
+ @bookmarkManager={{this.topicBookmarkManager}}
+ @buttonClasses={{@buttonClasses}}
+ ...attributes
+ />
+ {{/if}}
+ </template>
+}
diff --git a/frontend/discourse/app/components/topic-footer-buttons.gjs b/frontend/discourse/app/components/topic-footer-buttons.gjs
index 0252c7b098d..e9f32b3585f 100644
--- a/frontend/discourse/app/components/topic-footer-buttons.gjs
+++ b/frontend/discourse/app/components/topic-footer-buttons.gjs
@@ -3,15 +3,14 @@ import Component from "@ember/component";
import { concat, hash } from "@ember/helper";
import { computed } from "@ember/object";
import { alias, or } from "@ember/object/computed";
-import { getOwner } from "@ember/owner";
import { compare } from "@ember/utils";
import { tagName } from "@ember-decorators/component";
-import BookmarkMenu from "discourse/components/bookmark-menu";
import DButton from "discourse/components/d-button";
import DropdownMenu from "discourse/components/dropdown-menu";
import PinnedButton from "discourse/components/pinned-button";
import PluginOutlet from "discourse/components/plugin-outlet";
import TopicAdminMenu from "discourse/components/topic-admin-menu";
+import TopicBookmarksMenu from "discourse/components/topic-bookmarks-menu";
import UserTip from "discourse/components/user-tip";
import DMenu from "discourse/float-kit/components/d-menu";
import concatClass from "discourse/helpers/concat-class";
@@ -20,7 +19,6 @@ import lazyHash from "discourse/helpers/lazy-hash";
import { NotificationLevels } from "discourse/lib/notification-levels";
import { getTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
import { getTopicFooterDropdowns } from "discourse/lib/register-topic-footer-dropdown";
-import TopicBookmarkManager from "discourse/lib/topic-bookmark-manager";
import DropdownSelectBox from "discourse/select-kit/components/dropdown-select-box";
import TopicNotificationsButton from "discourse/select-kit/components/topic-notifications-button";
import { eq, gt } from "discourse/truth-helpers";
@@ -65,11 +63,6 @@ export default class TopicFooterButtons extends Component {
);
}
- @computed("topic.bookmarked")
- get topicBookmarkManager() {
- return new TopicBookmarkManager(getOwner(this), this.topic);
- }
-
get dropdownButtons() {
return this.inlineButtons.filter((button) => button.dropdown);
}
@@ -145,9 +138,9 @@ export default class TopicFooterButtons extends Component {
{{#each this.inlineActionables key="id" as |actionable|}}
{{#if (eq actionable.type "inline-button")}}
{{#if (eq actionable.id "bookmark")}}
- <BookmarkMenu
+ <TopicBookmarksMenu
+ @topic={{this.topic}}
@showLabel={{this.showBookmarkLabel}}
- @bookmarkManager={{this.topicBookmarkManager}}
@buttonClasses="btn-default topic-footer-button"
/>
{{else}}
diff --git a/frontend/discourse/app/lib/post-bookmark-manager.js b/frontend/discourse/app/lib/post-bookmark-manager.js
index 86c8c1b5893..07007a243a1 100644
--- a/frontend/discourse/app/lib/post-bookmark-manager.js
+++ b/frontend/discourse/app/lib/post-bookmark-manager.js
@@ -32,6 +32,8 @@ export default class PostBookmarkManager {
.create(this.trackedBookmark)
.then((updatedBookmark) => {
this.trackedBookmark = updatedBookmark;
+ this._syncBookmarks(updatedBookmark.saveData);
+ this.model.createBookmark(updatedBookmark.saveData);
});
}
@@ -70,15 +72,17 @@ export default class PostBookmarkManager {
}
_syncBookmarks(data) {
- if (!this.topicController.bookmarks) {
- this.topicController.bookmarks = [];
+ if (!this.topicController.model.bookmarks) {
+ this.topicController.model.set("bookmarks", []);
}
- const bookmark = this.topicController.bookmarks.find(
+ const bookmark = this.topicController.model.bookmarks.find(
(b) => b.id === data.id
);
if (!bookmark) {
- this.topicController.bookmarks.push(Bookmark.create(data));
+ this.topicController.model.bookmarks.push(
+ Bookmark.create({ ...data, post_number: this.model.post_number })
+ );
} else {
bookmark.reminder_at = data.reminder_at;
bookmark.name = data.name;
diff --git a/frontend/discourse/app/lib/topic-bookmark-manager.js b/frontend/discourse/app/lib/topic-bookmark-manager.js
index decb56af467..5bb90113d9d 100644
--- a/frontend/discourse/app/lib/topic-bookmark-manager.js
+++ b/frontend/discourse/app/lib/topic-bookmark-manager.js
@@ -32,6 +32,9 @@ export default class TopicBookmarkManager {
.create(this.trackedBookmark)
.then((updatedBookmark) => {
this.trackedBookmark = updatedBookmark;
+ this._syncBookmarks(updatedBookmark.saveData);
+ this.topicController.model.set("bookmarked", true);
+ this.topicController.model.incrementProperty("bookmarksWereChanged");
});
}
@@ -72,15 +75,15 @@ export default class TopicBookmarkManager {
}
_syncBookmarks(data) {
- if (!this.topicController.bookmarks) {
- this.topicController.set("bookmarks", []);
+ if (!this.topicController.model.bookmarks) {
+ this.topicController.model.set("bookmarks", []);
}
- const bookmark = this.topicController.bookmarks.find(
+ const bookmark = this.topicController.model.bookmarks.find(
(b) => b.id === data.id
);
if (!bookmark) {
- this.topicController.bookmarks.push(Bookmark.create(data));
+ this.topicController.model.bookmarks.push(Bookmark.create(data));
} else {
bookmark.reminder_at = data.reminder_at;
bookmark.name = data.name;
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 92ba9aaff8e..42bb282c783 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -553,6 +553,7 @@ class TopicView
:reminder_at,
:name,
:auto_delete_preference,
+ "posts.post_number",
)
end
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/group/reports/show.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/group/reports/show.js
index c5ad69a47e4..50ed8304e0f 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/group/reports/show.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/group/reports/show.js
@@ -11,6 +11,7 @@ import {
NO_REMINDER_ICON,
WITH_REMINDER_ICON,
} from "discourse/models/bookmark";
+import { i18n } from "discourse-i18n";
import { ParamValidationError } from "discourse/plugins/discourse-data-explorer/discourse/components/param-input-form";
export default class GroupReportsShowController extends Controller {
@@ -38,8 +39,8 @@ export default class GroupReportsShowController extends Controller {
get bookmarkLabel() {
return this.queryGroupBookmark
- ? "bookmarked.edit_bookmark"
- : "bookmarked.title";
+ ? i18n("bookmarked.edit_bookmark", { count: 1 })
+ : i18n("bookmarked.title");
}
get bookmarkIcon() {
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
index 26dcb790ae3..678196919a7 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
@@ -30,7 +30,7 @@ export default <template>
<DButton
@action={{@controller.toggleBookmark}}
- @label={{@controller.bookmarkLabel}}
+ @translatedLabel={{@controller.bookmarkLabel}}
@icon={{@controller.bookmarkIcon}}
class={{@controller.bookmarkClassName}}
/>
diff --git a/spec/system/bookmarks_spec.rb b/spec/system/bookmarks_spec.rb
index f1116b9bbba..5b46efd35fe 100644
--- a/spec/system/bookmarks_spec.rb
+++ b/spec/system/bookmarks_spec.rb
@@ -145,6 +145,75 @@ describe "Bookmarking posts and topics" do
end
end
+ describe "topic footer bookmark button with post bookmarks" do
+ it "shows jump/edit/delete for a single post bookmark" do
+ Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
+ topic_page.visit_topic(topic)
+
+ expect(bookmark_menu).to have_topic_bookmark_button_label(
+ I18n.t("js.bookmarked.edit_bookmark", count: 1),
+ )
+
+ bookmark_menu.click_topic_bookmark_button
+ expect(bookmark_menu).to have_jump_to_post_option(post_2.post_number)
+ expect(page).to have_css(".topic-bookmarks-menu-content [data-menu-option-id='edit']")
+ expect(page).to have_css(".topic-bookmarks-menu-content [data-menu-option-id='delete']")
+ end
+
+ it "shows plural label, correct tooltip, and grouped menu for multiple bookmarks" do
+ Fabricate(:bookmark, bookmarkable: topic, user: current_user)
+ Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
+ topic_page.visit_topic(topic)
+
+ expect(bookmark_menu).to have_topic_bookmark_button_label(
+ I18n.t("js.bookmarked.edit_bookmark", count: 2),
+ )
+ expect(bookmark_menu).to have_topic_bookmark_button_title(
+ I18n.t("js.bookmarked.edit_bookmark", count: 2),
+ )
+
+ bookmark_menu.click_topic_bookmark_button
+ expect(bookmark_menu).to have_jump_to_post_option(post_2.post_number)
+ expect(bookmark_menu).to have_edit_topic_bookmark_option
+ expect(bookmark_menu).to have_delete_topic_bookmark_option
+ expect(bookmark_menu).to have_clear_all_option
+ end
+
+ it "navigates to the bookmarked post when clicking jump" do
+ Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
+ topic_page.visit_topic(topic)
+
+ bookmark_menu.click_topic_bookmark_button
+ bookmark_menu.click_jump_to_post(post_2.post_number)
+
+ expect(page).to have_current_path(%r{/t/.*#{topic.id}/#{post_2.post_number}})
+ end
+
+ it "deletes a single post bookmark from the footer menu" do
+ Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
+ topic_page.visit_topic(topic)
+
+ bookmark_menu.click_topic_bookmark_button
+ bookmark_menu.click_menu_option("delete")
+
+ expect(topic_page).to have_no_bookmarks(topic)
+ expect(Bookmark.where(user: current_user, bookmarkable: post_2)).not_to exist
+ end
+
+ it "live updates footer button when bookmarking a post" do
+ topic_page.visit_topic(topic)
+ expect(topic_page).to have_no_bookmarks(topic)
+
+ topic_page.expand_post_actions(post)
+ topic_page.click_post_action_button(post, :bookmark)
+ expect(topic_page).to have_post_bookmarked(post, with_reminder: false)
+
+ expect(bookmark_menu).to have_topic_bookmark_button_label(
+ I18n.t("js.bookmarked.edit_bookmark", count: 1),
+ )
+ end
+ end
+
describe "editing existing bookmarks" do
fab!(:bookmark) do
Fabricate(
diff --git a/spec/system/page_objects/components/bookmark_menu.rb b/spec/system/page_objects/components/bookmark_menu.rb
index 8343d4d57fa..f713c41d1bc 100644
--- a/spec/system/page_objects/components/bookmark_menu.rb
+++ b/spec/system/page_objects/components/bookmark_menu.rb
@@ -10,6 +10,58 @@ module PageObjects
def open?
has_css?(".bookmark-menu-content")
end
+
+ def topic_bookmark_button
+ find("#topic-footer-buttons .bookmark-menu__trigger")
+ end
+
+ def click_topic_bookmark_button
+ topic_bookmark_button.click
+ end
+
+ def has_topic_bookmark_button_label?(text)
+ has_css?("#topic-footer-buttons .bookmark-menu__trigger", text: text)
+ end
+
+ def has_topic_bookmark_button_title?(title)
+ has_css?("#topic-footer-buttons .bookmark-menu__trigger[title='#{title}']")
+ end
+
+ def topic_bookmarks_menu_open?
+ has_css?(".topic-bookmarks-menu-content")
+ end
+
+ def has_jump_to_post_option?(post_number)
+ has_css?(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='jump']",
+ text: "##{post_number}",
+ )
+ end
+
+ def click_jump_to_post(post_number)
+ find(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='jump']",
+ text: "##{post_number}",
+ ).click
+ end
+
+ def has_clear_all_option?
+ has_css?(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='clear-all']",
+ )
+ end
+
+ def has_edit_topic_bookmark_option?
+ has_css?(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='edit-topic-bookmark']",
+ )
+ end
+
+ def has_delete_topic_bookmark_option?
+ has_css?(
+ ".topic-bookmarks-menu-content .bookmark-menu__row[data-menu-option-id='delete-topic-bookmark']",
+ )
+ end
end
end
end
diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb
index 3ed0e123285..b4e42eb1b63 100644
--- a/spec/system/page_objects/pages/topic.rb
+++ b/spec/system/page_objects/pages/topic.rb
@@ -216,7 +216,7 @@ module PageObjects
def has_topic_bookmarked?(topic)
within_topic_footer_buttons do
- has_css?(".bookmark-menu-trigger.bookmarked", text: "Edit Bookmark")
+ has_css?(".bookmark-menu-trigger.bookmarked", text: "Edit bookmark")
end
end