FIX: Hide old bookmark button on post-menu if SiteSetting.enable_bookmarks_with_reminders

Hide old bookmark post-menu item if the site setting for the new bookmark reminders is enabled and change icon for the new bookmark functionality to the same as the old bookmark button
Fix null @topic_view error in post serializer for post_bookmark, as new posts do not have a @topic_view
This commit is contained in:
Martin Brennan 2019-12-12 16:28:01 +10:00 committed by GitHub
parent 9d6a9bba96
commit 9f4c9bafa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -332,7 +332,7 @@ registerButton("bookmarkWithReminder", (attrs, state, siteSettings) => {
title,
titleOptions,
className: classNames.join(" "),
icon: "book"
icon: "bookmark"
};
});
@ -460,7 +460,16 @@ export default createWidget("post-menu", {
const allButtons = [];
let visibleButtons = [];
const orderedButtons = this.menuItems();
// filter menu items based on site settings
const orderedButtons = this.menuItems().filter(button => {
if (
this.siteSettings.enable_bookmarks_with_reminders &&
button === "bookmark"
) {
return false;
}
return true;
});
// If the post is a wiki, make Edit more prominent
if (attrs.wiki && attrs.canEdit) {

View File

@ -330,7 +330,7 @@ class PostSerializer < BasicPostSerializer
end
def post_bookmark
return nil if !SiteSetting.enable_bookmarks_with_reminders?
return nil if !SiteSetting.enable_bookmarks_with_reminders? || @topic_view.blank?
@post_bookmark ||= @topic_view.user_post_bookmarks.find { |bookmark| bookmark.post_id == object.id }
end

View File

@ -227,10 +227,11 @@ describe PostSerializer do
context "post with bookmarks" do
let(:current_user) { Fabricate(:user) }
let(:topic_view) { TopicView.new(post.topic, current_user) }
let(:serialized) do
s = serialized_post(current_user)
s.post_actions = PostAction.counts_for([post], current_user)[post.id]
s.topic_view = TopicView.new(post.topic, current_user)
s.topic_view = topic_view
s
end
@ -265,10 +266,18 @@ describe PostSerializer do
it "returns the reminder_at for the bookmark" do
expect(serialized.as_json[:bookmark_reminder_at]).to eq(bookmark.reminder_at.iso8601)
end
context "if topic_view is blank" do
let(:topic_view) { nil }
it "does not return the bookmarked_with_reminder attribute" do
expect(serialized.as_json.key?(:bookmarked_with_reminder)).to eq(false)
end
end
end
context "when the site setting for bookmarks with reminders is disabled" do
it "does not return the bookmarked attribute" do
it "does not return the bookmarked_with_reminder attribute" do
expect(serialized.as_json.key?(:bookmarked_with_reminder)).to eq(false)
end