diff --git a/app/assets/javascripts/discourse/app/components/bookmark-icon.js b/app/assets/javascripts/discourse/app/components/bookmark-icon.js index 6862a1011a2..ca18e28607f 100644 --- a/app/assets/javascripts/discourse/app/components/bookmark-icon.js +++ b/app/assets/javascripts/discourse/app/components/bookmark-icon.js @@ -14,6 +14,10 @@ export default class BookmarkIcon extends Component { @computed("bookmark.reminder_at") get icon() { + if (!this.bookmark) { + return NO_REMINDER_ICON; + } + if (!isEmpty(this.bookmark.reminder_at)) { return WITH_REMINDER_ICON; } @@ -21,8 +25,19 @@ export default class BookmarkIcon extends Component { return NO_REMINDER_ICON; } + @computed("bookmark") + get cssClasses() { + return this.bookmark + ? "bookmark-icon bookmark-icon__bookmarked" + : "bookmark-icon"; + } + @computed("bookmark.name", "bookmark.reminder_at") get title() { + if (!this.bookmark) { + return I18n.t("bookmarks.create"); + } + if (!isEmpty(this.bookmark.reminder_at)) { const formattedTime = formattedReminderTime( this.bookmark.reminder_at, diff --git a/app/assets/javascripts/discourse/app/templates/components/bookmark-icon.hbs b/app/assets/javascripts/discourse/app/templates/components/bookmark-icon.hbs index 5f627db1de1..2a1a2af91c1 100644 --- a/app/assets/javascripts/discourse/app/templates/components/bookmark-icon.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/bookmark-icon.hbs @@ -1 +1 @@ -{{d-icon icon translatedtitle=title}} +{{d-icon icon translatedtitle=title class=cssClasses}} diff --git a/app/assets/javascripts/discourse/tests/integration/components/bookmark-icon-test.js b/app/assets/javascripts/discourse/tests/integration/components/bookmark-icon-test.js index e68d2db5ecd..cbe228ec034 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/bookmark-icon-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/bookmark-icon-test.js @@ -29,7 +29,9 @@ discourseModule("Component | bookmark-icon", function (hooks) { }, async test(assert) { - assert.ok(exists(".d-icon-discourse-bookmark-clock")); + assert.ok( + exists(".d-icon-discourse-bookmark-clock.bookmark-icon__bookmarked") + ); assert.strictEqual( query(".svg-icon-title")["title"], I18n.t("bookmarks.created_with_reminder_generic", { @@ -56,7 +58,7 @@ discourseModule("Component | bookmark-icon", function (hooks) { }, async test(assert) { - assert.ok(exists(".d-icon-bookmark")); + assert.ok(exists(".d-icon-bookmark.bookmark-icon__bookmarked")); assert.strictEqual( query(".svg-icon-title")["title"], I18n.t("bookmarks.created_generic", { @@ -65,4 +67,22 @@ discourseModule("Component | bookmark-icon", function (hooks) { ); }, }); + + componentTest("null bookmark", { + template: hbs`{{bookmark-icon bookmark=bookmark}}`, + + beforeEach() { + this.setProperties({ + bookmark: null, + }); + }, + + async test(assert) { + assert.ok(exists(".d-icon-bookmark.bookmark-icon")); + assert.strictEqual( + query(".svg-icon-title")["title"], + I18n.t("bookmarks.create") + ); + }, + }); });