From 9abdb68bc508724ab42af7d7de52718990e1a2bd Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Thu, 10 Sep 2026 17:41:36 +0300 Subject: [PATCH] make submission header buttons native --- app/javascript/elements/clipboard_copy.js | 4 +- app/javascript/elements/download_button.js | 4 + app/javascript/elements/native_action.js | 2 +- app/views/shared/_clipboard_copy.html.erb | 2 +- app/views/submissions/show.html.erb | 122 ++++++++++++--------- 5 files changed, 79 insertions(+), 55 deletions(-) diff --git a/app/javascript/elements/clipboard_copy.js b/app/javascript/elements/clipboard_copy.js index 4118b9e2f..f6e492bc9 100644 --- a/app/javascript/elements/clipboard_copy.js +++ b/app/javascript/elements/clipboard_copy.js @@ -6,7 +6,9 @@ export default class extends HTMLElement { const text = this.dataset.text || this.innerText.trim() if (navigator.clipboard) { - navigator.clipboard.writeText(text) + navigator.clipboard.writeText(text).then(() => { + window.webkit?.messageHandlers?.flash?.postMessage({ style: 'notice', message: this.dataset.copied }) + }) } else { if (e.target.tagName !== 'INPUT') { alert(`Clipboard not available. Make sure you're using https://\nCopy text: ${text}`) diff --git a/app/javascript/elements/download_button.js b/app/javascript/elements/download_button.js index 2a4b62104..07145f506 100644 --- a/app/javascript/elements/download_button.js +++ b/app/javascript/elements/download_button.js @@ -21,6 +21,10 @@ export default targetable(class extends HTMLElement { downloadFiles () { if (!this.dataset.src) return + const download = window.webkit?.messageHandlers?.download + + if (download) return download.postMessage({ src: this.dataset.src }) + this.toggleState() fetch(this.dataset.src).then(async (response) => { diff --git a/app/javascript/elements/native_action.js b/app/javascript/elements/native_action.js index 27119b812..912763a39 100644 --- a/app/javascript/elements/native_action.js +++ b/app/javascript/elements/native_action.js @@ -6,7 +6,7 @@ export default class extends HTMLElement { if (!bridge) return - const target = this.querySelector('a, button, [role="button"]') + const target = this.querySelector('a, button, [role="button"]') || this.firstElementChild if (!target) return diff --git a/app/views/shared/_clipboard_copy.html.erb b/app/views/shared/_clipboard_copy.html.erb index b3fe3720e..8601cf2d2 100644 --- a/app/views/shared/_clipboard_copy.html.erb +++ b/app/views/shared/_clipboard_copy.html.erb @@ -1,4 +1,4 @@ - +