diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 001f1e48d63..ea07d121f0b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -285,7 +285,8 @@ module ApplicationHelper def body_data_attributes(local_assigns) { - controller: "application auto-theme-switcher hover-card-trigger beforeunload external-links highlight-target-element", + controller: ["application auto-theme-switcher hover-card-trigger beforeunload external-links highlight-target-element", + stimulus_body_controller].compact.join(" "), relative_url_root: root_path, overflowing_identifier: ".__overflowing_body", external_links_enabled_value: Setting.capture_external_links?, diff --git a/app/helpers/stimulus_helper.rb b/app/helpers/stimulus_helper.rb index 33545acd811..afb619e9b61 100644 --- a/app/helpers/stimulus_helper.rb +++ b/app/helpers/stimulus_helper.rb @@ -39,5 +39,13 @@ module StimulusHelper @stimulus_content_data || {} end + def body_controller(name) + @stimulus_body_controller = name + end + + def stimulus_body_controller + @stimulus_body_controller + end + # rubocop:enable Rails/HelperInstanceVariable end diff --git a/frontend/src/stimulus/controllers/keep-scroll-position.controller.ts b/frontend/src/stimulus/controllers/keep-scroll-position.controller.ts index 17ac82b2cf2..a56a7cd0fe3 100644 --- a/frontend/src/stimulus/controllers/keep-scroll-position.controller.ts +++ b/frontend/src/stimulus/controllers/keep-scroll-position.controller.ts @@ -31,16 +31,10 @@ import { ApplicationController } from 'stimulus-use'; export default class KeepScrollPositionController extends ApplicationController { - static values = { - url: String, - }; - static targets = ['triggerButton']; declare triggerButtonTarget:HTMLLinkElement; - declare urlValue:string; - connect() { super.connect(); @@ -80,6 +74,6 @@ export default class KeepScrollPositionController extends ApplicationController } private scrollPositionKey():string { - return `${this.urlValue}/scrollPosition`; + return `${window.location.pathname}/scrollPosition`; } } diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb index 9da1ca193f9..67e98443def 100644 --- a/modules/meeting/app/components/meetings/header_component.html.erb +++ b/modules/meeting/app/components/meetings/header_component.html.erb @@ -1,8 +1,8 @@ <%= - helpers.content_controller "poll-for-changes keep-scroll-position", + helpers.content_controller "poll-for-changes", poll_for_changes_url_value: check_for_updates_project_meeting_path(@meeting.project, @meeting), - poll_for_changes_interval_value: check_for_updates_interval, - keep_scroll_position_url_value: meeting_path(@meeting) + poll_for_changes_interval_value: check_for_updates_interval + helpers.body_controller "keep-scroll-position" component_wrapper do render( diff --git a/modules/meeting/app/components/meetings/index_page_header_component.html.erb b/modules/meeting/app/components/meetings/index_page_header_component.html.erb index 6e05000b7c4..f28c8e3eab8 100644 --- a/modules/meeting/app/components/meetings/index_page_header_component.html.erb +++ b/modules/meeting/app/components/meetings/index_page_header_component.html.erb @@ -1,5 +1,4 @@ -<% helpers.content_controller "keep-scroll-position", - keep_scroll_position_url_value: polymorphic_path([@project, :meetings]) %> +<% helpers.content_controller "keep-scroll-position" %> <%= render(Primer::OpenProject::PageHeader.new) do |header| header.with_title { page_title } diff --git a/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb b/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb index 05005d81a6b..bbbd4295ebd 100644 --- a/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb +++ b/modules/meeting/app/components/recurring_meetings/show_page_header_component.html.erb @@ -1,6 +1,5 @@ <%= - helpers.content_controller "keep-scroll-position", - keep_scroll_position_url_value: polymorphic_path([@project, @meeting]) + helpers.content_controller "keep-scroll-position" component_wrapper do render(Primer::OpenProject::PageHeader.new) do |header|