Skip to content

Commit

Permalink
Move the reference value back to the header
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Sep 27, 2024
1 parent 750ef9d commit b588816
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions frontend/src/stimulus/controllers/poll-for-changes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export default class PollForChangesController extends ApplicationController {
autoscrollEnabled: Boolean,
};

static targets = ['reloadButton'];
static targets = ['reloadButton', 'reference'];

declare reloadButtonTarget:HTMLLinkElement;
declare referenceTarget:HTMLElement;
declare readonly hasReferenceTarget:boolean;

declare referenceValue:string;
declare urlValue:string;
Expand Down Expand Up @@ -69,12 +71,20 @@ export default class PollForChangesController extends ApplicationController {
clearInterval(this.interval);
}

buildReference():string {
if (this.hasReferenceTarget) {
return this.referenceTarget.dataset.referenceValue as string;
}

return this.referenceValue;
}

reloadButtonTargetConnected() {
this.reloadButtonTarget.addEventListener('click', this.rememberCurrentScrollPosition.bind(this));
}

triggerTurboStream() {
void fetch(`${this.urlValue}?reference=${this.referenceValue}`, {
void fetch(`${this.urlValue}?reference=${this.buildReference()}`, {
headers: {
Accept: 'text/vnd.turbo-stream.html',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<%=
helpers.content_controller "poll-for-changes",
poll_for_changes_reference_value: @meeting.changed_hash,
poll_for_changes_url_value: check_for_updates_meeting_path(@meeting),
poll_for_changes_interval_value: check_for_updates_interval,
poll_for_changes_autoscroll_enabled_value: true

component_wrapper do
render(Primer::OpenProject::PageHeader.new(
test_selector: "meeting-page-header",
state: @state
state: @state,
data: {
poll_for_changes_target: "reference",
reference_value: @meeting.changed_hash
}
)) do |header|
header.with_title do |title|
title.with_editable_form(model: @meeting,
Expand Down

0 comments on commit b588816

Please sign in to comment.