FIX: use async versions of clipboardCopy (#389)

Chrome and Firefox work with standard clipboardCopy, but since
we are making an ajax call Safari fails cause there is too much
delay detected.

To avoid this issue we trade in promises which are acceptable and
work in iOS.
This commit is contained in:
Sam 2023-12-29 22:50:10 +11:00 committed by GitHub
parent 73c58155f8
commit c9b109f9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -1,8 +1,17 @@
import { ajax } from "discourse/lib/ajax";
import { clipboardCopy } from "discourse/lib/utilities";
import { clipboardCopyAsync } from "discourse/lib/utilities";
import I18n from "discourse-i18n";
export default async function (topic, fromPostNumber, toPostNumber) {
await clipboardCopyAsync(async () => {
const text = await generateClipboard(topic, fromPostNumber, toPostNumber);
return new Blob([text], {
type: "text/plain",
});
});
}
async function generateClipboard(topic, fromPostNumber, toPostNumber) {
const stream = topic.get("postStream");
let postNumbers = [];
@ -51,5 +60,5 @@ export default async function (topic, fromPostNumber, toPostNumber) {
window.discourseAiClipboard = text;
}
await clipboardCopy(text);
return text;
}