A platform for community discussion. Free, open, simple.
UX: add toggle to topic voting menu to change notification level to "watching" (#39097)
Krisd1b96e8fe4f7
diff --git a/app/assets/stylesheets/common/float-kit/d-menu.scss b/app/assets/stylesheets/common/float-kit/d-menu.scssindex e7fb3bfee10..63af9df7feb 100644--- a/app/assets/stylesheets/common/float-kit/d-menu.scss+++ b/app/assets/stylesheets/common/float-kit/d-menu.scss@@ -136,7 +136,6 @@}&:hover,- &:focus,&:focus-visible {.discourse-no-touch & {background: var(--d-hover);diff --git a/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs b/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjsindex 2943c18e1b0..ed127235d05 100644--- a/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs+++ b/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs@@ -7,6 +7,7 @@ import DropdownMenu from "discourse/components/dropdown-menu";import DMenu from "discourse/float-kit/components/d-menu";import DTooltip from "discourse/float-kit/components/d-tooltip";import icon from "discourse/helpers/d-icon";+import { NotificationLevels } from "discourse/lib/notification-levels";import { applyBehaviorTransformer } from "discourse/lib/transformer";import { and, eq, not } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";@@ -26,6 +27,12 @@ export default class VoteBox extends Component {return this.topic.user_voted ? "vote-up-filled" : "vote-up";}+ get isWatching() {+ return (+ this.topic.details?.notification_level === NotificationLevels.WATCHING+ );+ }+get limitsEnabled() {return this.currentUser?.vote_limit != null;}@@ -118,6 +125,14 @@ export default class VoteBox extends Component {this.dMenu.close();}+ @action+ async toggleWatching() {+ const newLevel = this.isWatching+ ? NotificationLevels.REGULAR+ : NotificationLevels.WATCHING;+ await this.topic.details.updateNotifications(newLevel);+ }+@actiononRegisterApi(api) {this.dMenu = api;@@ -179,6 +194,14 @@ export default class VoteBox extends Component {class="btn-transparent remove-vote topic-voting-menu__row-btn"/></dropdown.item>+ <dropdown.item class="topic-voting-menu__watch-toggle">+ <DButton+ @translatedLabel={{i18n "topic_voting.watch_topic"}}+ @action={{this.toggleWatching}}+ @icon={{if this.isWatching "toggle-on" "toggle-off"}}+ class="btn-transparent topic-voting-menu__row-btn"+ />+ </dropdown.item>{{else if (eq this.currentUser.vote_limit 0)}}<dropdown.item class="topic-voting-menu__title --locked">{{icon "lock"}}@@ -221,6 +244,14 @@ export default class VoteBox extends Component {class="btn-transparent remove-vote topic-voting-menu__row-btn"/></dropdown.item>+ <dropdown.item class="topic-voting-menu__watch-toggle">+ <DButton+ @translatedLabel={{i18n "topic_voting.watch_topic"}}+ @action={{this.toggleWatching}}+ @icon={{if this.isWatching "toggle-on" "toggle-off"}}+ class="btn-transparent topic-voting-menu__row-btn"+ />+ </dropdown.item>{{/if}}{{/if}}</DropdownMenu>diff --git a/plugins/discourse-topic-voting/assets/stylesheets/common/topic-voting.scss b/plugins/discourse-topic-voting/assets/stylesheets/common/topic-voting.scssindex f8e9d7eeee2..f2f7c2b0ebf 100644--- a/plugins/discourse-topic-voting/assets/stylesheets/common/topic-voting.scss+++ b/plugins/discourse-topic-voting/assets/stylesheets/common/topic-voting.scss@@ -167,3 +167,17 @@display: none;}}++.topic-voting-menu__watch-toggle {+ .d-icon-toggle-on {+ color: var(--tertiary);+ }++ .discourse-no-touch & {+ .btn:hover {+ .d-icon-toggle-on {+ color: var(--tertiary);+ }+ }+ }+}diff --git a/plugins/discourse-topic-voting/config/locales/client.en.yml b/plugins/discourse-topic-voting/config/locales/client.en.ymlindex 4fffb1781c3..2d33b0d5487 100755--- a/plugins/discourse-topic-voting/config/locales/client.en.yml+++ b/plugins/discourse-topic-voting/config/locales/client.en.yml@@ -31,6 +31,7 @@ en:one: "Vote"other: "Votes"remove_vote: "Remove vote"+ watch_topic: "Notify me about new posts"no_votes_yet: "No one has voted for this yet"and_more_voters: "and %{count} more..."show_voters: "Show who voted"diff --git a/plugins/discourse-topic-voting/spec/system/page_objects/pages/topic.rb b/plugins/discourse-topic-voting/spec/system/page_objects/pages/topic.rbindex cf906882e68..d0df51a94b9 100644--- a/plugins/discourse-topic-voting/spec/system/page_objects/pages/topic.rb+++ b/plugins/discourse-topic-voting/spec/system/page_objects/pages/topic.rb@@ -42,6 +42,19 @@ module TopicVotingTopichas_css?(".title-voting button.voting-wrapper__button.btn-default") &&has_no_css?(".title-voting button.voting-wrapper__button.btn-success")end++ def click_watch_toggle+ find(".topic-voting-menu__watch-toggle .btn").click+ self+ end++ def has_watch_toggle_on?+ has_css?(".topic-voting-menu__watch-toggle .d-icon-toggle-on")+ end++ def has_watch_toggle_off?+ has_css?(".topic-voting-menu__watch-toggle .d-icon-toggle-off")+ endendPageObjects::Pages::Topic.include(TopicVotingTopic)diff --git a/plugins/discourse-topic-voting/spec/system/voting_spec.rb b/plugins/discourse-topic-voting/spec/system/voting_spec.rbindex 1e33e916360..6d025ceeacb 100644--- a/plugins/discourse-topic-voting/spec/system/voting_spec.rb+++ b/plugins/discourse-topic-voting/spec/system/voting_spec.rb@@ -95,6 +95,25 @@ RSpec.describe "Topic voting" doendend+ context "when toggling watch from the vote menu" do+ fab!(:voting_post) { Fabricate(:post, topic: voting_topic1) }++ before { DiscourseTopicVoting::CategorySetting.create!(category: voting_category) }++ it "sets the topic to watching" do+ visit("/t/#{voting_topic1.slug}/#{voting_topic1.id}")++ topic_page.vote+ expect(topic_page).to have_watch_toggle_off++ topic_page.click_watch_toggle+ expect(topic_page).to have_watch_toggle_on+ expect(TopicUser.find_by(user: admin, topic: voting_topic1).notification_level).to eq(+ TopicUser.notification_levels[:watching],+ )+ end+ end+context "when viewing a closed voting topic without having voted" dobefore { DiscourseTopicVoting::CategorySetting.create!(category: voting_category) }