Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/javascript/controllers/bridge/buttons_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ export default class extends BridgeComponent {
static component = "buttons"
static targets = [ "button" ]

connect() {
super.connect()

if (!this.beforeUnloadHandler) {
this.beforeUnloadHandler = this.handleBeforeUnload.bind(this)
}

window.addEventListener("beforeunload", this.beforeUnloadHandler)
}
Comment thread
jayohms marked this conversation as resolved.

disconnect() {
super.disconnect()

if (this.beforeUnloadHandler) {
window.removeEventListener("beforeunload", this.beforeUnloadHandler)
}
Comment thread
jayohms marked this conversation as resolved.
Comment thread
jayohms marked this conversation as resolved.

this.notifyBridgeOfDisconnect()
}

buttonTargetConnected() {
this.notifyBridgeOfConnect()
}
Expand All @@ -27,6 +47,14 @@ export default class extends BridgeComponent {
})
}

notifyBridgeOfDisconnect() {
this.send("disconnect")
}

handleBeforeUnload() {
this.notifyBridgeOfDisconnect()
}

#clickButton(message) {
const selectedIndex = message.data.selectedIndex
this.#enabledButtonTargets[selectedIndex].click()
Expand Down
26 changes: 24 additions & 2 deletions app/javascript/controllers/bridge/form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@ export default class extends BridgeComponent {
static targets = [ "submit", "cancel" ]
static values = { submitTitle: String }

connect() {
super.connect()

if (!this.beforeUnloadHandler) {
this.beforeUnloadHandler = this.handleBeforeUnload.bind(this)
}

window.addEventListener("beforeunload", this.beforeUnloadHandler)
}
Comment thread
jayohms marked this conversation as resolved.

disconnect() {
super.disconnect()

if (this.beforeUnloadHandler) {
window.removeEventListener("beforeunload", this.beforeUnloadHandler)
}
Comment thread
jayohms marked this conversation as resolved.
Comment thread
jayohms marked this conversation as resolved.
}

submitTargetConnected() {
this.notifyBridgeOfConnect()
this.#observeSubmitTarget()
}

submitTargetDisconnected() {
this.notifyBridgeOfDisonnect()
this.notifyBridgeOfDisconnect()
this.submitObserver?.disconnect()
}

Expand All @@ -37,7 +55,7 @@ export default class extends BridgeComponent {
}
}

notifyBridgeOfDisonnect() {
notifyBridgeOfDisconnect() {
this.send("disconnect")
}

Expand All @@ -49,6 +67,10 @@ export default class extends BridgeComponent {
this.send("submitEnd")
}

handleBeforeUnload() {
this.notifyBridgeOfDisconnect()
}

#observeSubmitTarget() {
this.submitObserver = new MutationObserver(() => {
this.send(this.submitTarget.disabled ? "submitDisabled" : "submitEnabled")
Expand Down
1 change: 1 addition & 0 deletions app/views/cards/container/_closure.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= button_to card_closure_path(card), method: :delete, class: "btn btn--plain borderless fill-transparent" do %>
<span class="pad-inline-end">Undo</span>
<% end %>
<%= bridged_button_to_board(card.board) %>
</div>
<% else %>
<div class="card-perma__notch card-perma__notch--bottom">
Expand Down
2 changes: 2 additions & 0 deletions app/views/cards/container/_closure_buttons.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
<span class="overflow-ellipsis">Mark as Done</span>
<kbd class="txt-x-small hide-on-touch">d</kbd>
<% end %>

<%= bridged_button_to_board(card.board) %>
</div>
6 changes: 3 additions & 3 deletions app/views/cards/container/_image.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<% if card.image.attached? %>
<%= button_to card_image_path(card), method: :delete, class: "btn",
data: { controller: "tooltip", bridge__overflow_menu_target: "item", bridge_title: "Remove background image" } do %>
<%= button_to card_image_path(card), method: :delete, class: "btn hide-on-native",
data: { controller: "tooltip" } do %>
<%= icon_tag "picture-remove" %>
<span class="for-screen-reader">Remove background image</span>
<% end %>
<% elsif !card.closed? %>
<%= form_with model: card, data: { controller: "form" } do |form| %>
<label class="card-perma__image-btn btn input--file btn--circle-mobile" data-controller="tooltip" data-bridge--overflow-menu-target="item" data-bridge-title="Add background image">
<label class="card-perma__image-btn btn input--file btn--circle-mobile hide-on-native" data-controller="tooltip">
<%= icon_tag "picture-add" %>
<span class="for-screen-reader">Add background image</span>

Expand Down
1 change: 0 additions & 1 deletion app/views/cards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="header__actions header__actions--start">
<%= link_back_to_board(@card.board) %>
</div>
<%= bridged_button_to_board(@card.board) %>
<% end %>

<%= turbo_stream_from @card %>
Expand Down