A platform for community discussion. Free, open, simple.
UX: Show which attendance is selected on events (#42469)
Régis Hanol98d10a529990
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/status.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/status.gjsindex ce998e4d1e3..18c4b37b232 100644--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/status.gjs+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/status.gjs@@ -13,6 +13,9 @@ import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";import { i18n } from "discourse-i18n";+const statusButtonClass = (selected) =>+ selected ? "btn-primary" : "btn-default";+const GoingDropdown = <template><DDropdownMenu as |dropdown|><dropdown.item@@ -92,6 +95,14 @@ export default class DiscoursePostEventStatus extends Component {return this.watchingInviteeStatus === "going";}+ get isInterested() {+ return this.watchingInviteeStatus === "interested";+ }++ get isNotGoing() {+ return this.watchingInviteeStatus === "not_going";+ }+get isGoingThisEvent() {return this.isGoing && !this.args.event.watchingInvitee?.recurring;}@@ -228,7 +239,10 @@ export default class DiscoursePostEventStatus extends Component {{{#if @event.recurrence}}{{#if this.site.mobileView}}<DMenu- class="btn btn-default going-button"+ class={{dConcatClass+ "going-button"+ (statusButtonClass this.isGoing)+ }}@identifier="discourse-post-event-going-menu"@icon={{this.goingTriggerIcon}}@label={{this.goingTriggerLabel}}@@ -243,7 +257,8 @@ export default class DiscoursePostEventStatus extends Component {{{else}}<DComboButton class="going-button --has-menu" as |combo|><combo.Button- class="btn-default"+ class={{statusButtonClass this.isGoing}}+ @ariaPressed={{this.isGoing}}@disabled={{this.goingButtonDisabled}}@icon={{this.goingTriggerIcon}}@label={{if@@ -255,7 +270,7 @@ export default class DiscoursePostEventStatus extends Component {/><combo.Menu@identifier="discourse-post-event-going-menu"- @triggerClass="btn-default"+ @triggerClass={{statusButtonClass this.isGoing}}@disabled={{this.goingButtonDisabled}}@onRegisterApi={{this.registerGoingMenu}}>@@ -265,7 +280,11 @@ export default class DiscoursePostEventStatus extends Component {{{/if}}{{else}}<DButton- class="btn-default going-button"+ class={{dConcatClass+ "going-button"+ (statusButtonClass this.isGoing)+ }}+ @ariaPressed={{this.isGoing}}@disabled={{this.goingButtonDisabled}}@icon="check"@label={{if@@ -291,7 +310,11 @@ export default class DiscoursePostEventStatus extends Component {}}><DButton- class="btn-default interested-button"+ class={{dConcatClass+ "interested-button"+ (statusButtonClass this.isInterested)+ }}+ @ariaPressed={{this.isInterested}}@icon="star"@label="discourse_post_event.models.invitee.status.interested"@action={{fn this.changeWatchingInviteeStatus "interested"}}@@ -309,7 +332,11 @@ export default class DiscoursePostEventStatus extends Component {}}><DButton- class="btn-default not-going-button"+ class={{dConcatClass+ "not-going-button"+ (statusButtonClass this.isNotGoing)+ }}+ @ariaPressed={{this.isNotGoing}}@icon="xmark"@label="discourse_post_event.models.invitee.status.not_going"@action={{fn this.changeWatchingInviteeStatus "not_going"}}diff --git a/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss b/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scssindex 1e164706f0b..0025e83fd6e 100644--- a/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss+++ b/plugins/discourse-calendar/assets/stylesheets/common/discourse-post-event.scss@@ -273,19 +273,6 @@ $show-interested: inherit;display: $show-interested;}- &.status-going .going-button > .d-icon,- &.status-going .going-button .d-combo-button-button .d-icon {- color: var(--success);- }-- &.status-interested .interested-button .d-icon {- color: $interested;- }-- &.status-not_going .not-going-button .d-icon {- color: var(--danger);- }-.not-going-button span {white-space: nowrap;}diff --git a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rbindex ba392a40aed..74f3d3f7ebf 100644--- a/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb+++ b/plugins/discourse-calendar/spec/system/page_objects/discourse_calendar/post_event.rb@@ -6,6 +6,12 @@ module PageObjectsclass PostEvent < PageObjects::Pages::BaseTRIGGER_MENU_SELECTOR = ".discourse-post-event-more-menu-trigger"+ STATUS_BUTTONS = {+ going: ".going-button",+ interested: ".interested-button",+ not_going: ".not-going-button",+ }.freeze+def open_more_menutry_until_success dolocator("#{TRIGGER_MENU_SELECTOR}:not(.--saving)").click@@ -19,6 +25,11 @@ module PageObjectsselfend+ def not_going+ locator(".not-going-button").click+ self+ end+def has_going_menu?has_css?(".discourse-post-event-going-menu-trigger")end@@ -35,6 +46,18 @@ module PageObjectshas_css?(".event-status.status-going")end+ def has_selected_status?(status)+ has_css?(status_button_selector(status, ".btn-primary"))+ end++ def has_no_selected_status?(status)+ has_no_css?(status_button_selector(status, ".btn-primary"))+ end++ def has_pressed_status?(status, pressed: true)+ has_css?(status_button_selector(status, "[aria-pressed='#{pressed}']"))+ end+def has_going_count?(count)has_css?(".event-invitees-icon .going", text: count.to_s)end@@ -144,6 +167,13 @@ module PageObjectsdef editopen_more_menu { locator(".edit-event").click }end++ private++ def status_button_selector(status, state)+ button = ".event-status #{STATUS_BUTTONS.fetch(status)}"+ "#{button}#{state}, #{button} #{state}"+ endendendenddiff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rbindex 0689d97c22a..dec6aebbdf5 100644--- a/plugins/discourse-calendar/spec/system/post_event_spec.rb+++ b/plugins/discourse-calendar/spec/system/post_event_spec.rb@@ -290,6 +290,7 @@ describe "Post event" dopost_event_page.going_all_followingexpect(post_event_page).to have_going_status+ expect(post_event_page).to have_selected_status(:going)invitee = DiscoursePostEvent::Invitee.find_by(user_id: rsvp_user.id, post_id: post.id)expect(invitee.status).to eq(DiscoursePostEvent::Invitee.statuses[:going])expect(invitee.recurring).to eq(true)@@ -303,11 +304,35 @@ describe "Post event" dopost_event_page.going_this_eventexpect(post_event_page).to have_going_status+ expect(post_event_page).to have_selected_status(:going)invitee = DiscoursePostEvent::Invitee.find_by(user_id: rsvp_user.id, post_id: post.id)expect(invitee.status).to eq(DiscoursePostEvent::Invitee.statuses[:going])expect(invitee.recurring).to eq(false)end+ it "marks only the chosen attendance as selected" do+ raw = "[event status='public' start='2222-02-22 14:22']\n[/event]"+ post = PostCreator.create!(admin, title: "My test meetup event", raw:)++ visit(post.topic.url)++ expect(post_event_page).to have_no_selected_status(:going)+ expect(post_event_page).to have_pressed_status(:going, pressed: false)++ post_event_page.going++ expect(post_event_page).to have_selected_status(:going)+ expect(post_event_page).to have_pressed_status(:going)+ expect(post_event_page).to have_no_selected_status(:interested)+ expect(post_event_page).to have_no_selected_status(:not_going)++ post_event_page.not_going++ expect(post_event_page).to have_selected_status(:not_going)+ expect(post_event_page).to have_no_selected_status(:going)+ expect(post_event_page).to have_pressed_status(:going, pressed: false)+ end+it "renders without a dropdown on non-recurring events" doraw = "[event status='public' start='2222-02-22 14:22']\n[/event]"post = PostCreator.create!(admin, title: "My one-off meetup event", raw:)