stackchain-dashboard/frontend/issue-filing-receipt.js
timmy 6633ba5244
All checks were successful
CI / lint (pull_request) Successful in 1m44s
CI / build-release (pull_request) Successful in 5s
CI / browser-journey (pull_request) Successful in 59s
CI / release-candidate (pull_request) Has been skipped
feat: complete delegated mobile filing handoff (Closes #866)
2026-08-15 03:06:32 +00:00

78 lines
2.3 KiB
JavaScript

(function (root, factory) {
const api = factory();
if (typeof module === 'object' && module.exports) module.exports = api;
else root.createIssueFilingReceipt = api;
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
'use strict';
function createIssueFilingReceipt({
root, heading, key, title, ownership, openLink, shareButton,
fileAnotherButton, doneButton, status, navigator = {}, clipboard = navigator.clipboard,
onFileAnother = function () {},
}) {
let active = null;
let restoreFocus = null;
function close() {
root.hidden = true;
active = null;
const target = restoreFocus;
restoreFocus = null;
target?.focus?.();
}
async function share() {
if (!active) return;
const payload = {
title: active.repository + '#' + active.number + ' · ' + active.title,
text: active.title,
url: active.url,
};
if (typeof navigator.share === 'function') {
try {
await navigator.share(payload);
return;
} catch (error) {
if (error?.name === 'AbortError') return;
}
}
if (typeof clipboard?.writeText !== 'function') {
status.textContent = 'Issue link is ready in Open in Gitea.';
return;
}
await clipboard.writeText(active.url);
status.textContent = 'Issue link copied.';
}
function show(issue, returnTarget) {
active = issue;
restoreFocus = returnTarget || null;
key.textContent = issue.repository + '#' + issue.number;
title.textContent = issue.title;
ownership.textContent = issue.assignees?.length
? 'Assigned to @' + issue.assignees.join(', @') + '.'
: 'Created with no owner.';
openLink.href = issue.url;
status.textContent = '';
root.hidden = false;
heading.focus();
}
shareButton.addEventListener('click', share);
root.addEventListener('keydown', event => {
if (event.key !== 'Escape' || root.hidden) return;
event.preventDefault();
close();
});
doneButton.addEventListener('click', close);
fileAnotherButton.addEventListener('click', () => {
close();
onFileAnother();
});
return { show, close, share };
}
return createIssueFilingReceipt;
});