Workers P3-Endprüfung W2: Kopieren & öffnen meldet ein gescheitertes Kopieren ehrlich
copyTextChecked erfüllt nur, wenn der Text wirklich in der Zwischenablage liegt (Clipboard-API, sonst Notweg mit document.execCommand, dessen Rückgabewert jetzt geprüft wird; das Textfeld wird immer entfernt). copyText bleibt für die Kundenansicht die verschluckende Hülle. Das Pult nimmt die strenge Fassung, sodass die Zeile statt "Kopiert und geöffnet." den Hinweis zum Kopieren von Hand zeigt. Die Reihenfolge Kopieren vor Öffnen bleibt (Nutzer-Geste). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b2b45a0c7
commit
f6099938d8
4 files changed
+202
-12
No files matched your search
@@ -1,18 +1,39 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
export async function copyText(text) {
|
||||
// Strenge Fassung: erfüllt nur, wenn der Text wirklich in der Zwischenablage liegt, sonst Error('Kopieren fehlgeschlagen').
|
||||
// Erst die Clipboard-API, bei Ablehnung (kein Fokus, keine Berechtigung, unsicherer Kontext) der Notweg über ein Textfeld und
|
||||
// document.execCommand('copy'), das bei Misserfolg false liefert statt zu werfen. Der Aufruf von writeText geschieht synchron beim
|
||||
// Aufruf der Funktion (kein await davor): wer gleich danach window.open ruft, bleibt im Zug der Nutzer-Geste.
|
||||
export async function copyTextChecked(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
return
|
||||
} catch {
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = text
|
||||
textarea.setAttribute('readonly', '')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.left = '-9999px'
|
||||
// weiter mit dem Notweg
|
||||
}
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = text
|
||||
textarea.setAttribute('readonly', '')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.left = '-9999px'
|
||||
let ok = false
|
||||
try {
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
ok = document.execCommand('copy') === true
|
||||
} finally {
|
||||
textarea.parentNode?.removeChild(textarea)
|
||||
}
|
||||
if (!ok) throw new Error('Kopieren fehlgeschlagen')
|
||||
}
|
||||
|
||||
// Bisheriges Verhalten für die Kundenansicht: ein Fehlschlag wird verschluckt (die Aufrufer zeigen „Kopiert“ trotzdem).
|
||||
// Wer dem Menschen ehrlich melden muss, ob etwas in der Zwischenablage liegt (Pult: „Kopieren & öffnen“), nimmt copyTextChecked.
|
||||
export async function copyText(text) {
|
||||
try {
|
||||
await copyTextChecked(text)
|
||||
} catch {
|
||||
// bewusst still
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import Badge from '../ui/Badge'
|
||||
import Button from '../ui/Button'
|
||||
import EmptyState from '../ui/EmptyState'
|
||||
import { copyText } from '../CopyableCredential'
|
||||
import { copyTextChecked } from '../CopyableCredential'
|
||||
import { useEmployees } from '../../hooks/useEmployees'
|
||||
import { usePultFeed } from '../../hooks/usePultFeed'
|
||||
import { PULT_FILTERS, copyAndOpen, mailtoHref, rowModel } from '../../lib/workersPult'
|
||||
@@ -84,10 +84,12 @@ function PultRow({ api, item, row, text, onText, refresh, onFinished, onDetails
|
||||
}
|
||||
|
||||
// Kopieren & öffnen: copyAndOpen steht ganz vorn und ohne await davor, nur im Zug des Klicks darf der Browser den Tab öffnen.
|
||||
// Kopiert wird mit der strengen Fassung (copyTextChecked): scheitern Clipboard-API und Notweg, meldet die Zeile das ehrlich,
|
||||
// statt „Kopiert“ zu zeigen, während noch der alte Inhalt der Zwischenablage drinliegt.
|
||||
// Danach wird der Eintrag best-effort übernommen; ein Kollege, der schon dran ist, erscheint als Hinweis.
|
||||
const copyOpen = async () => {
|
||||
if (!begin()) return
|
||||
const result = await copyAndOpen({ text, url: row.sourceHref, copy: copyText, open: openTab })
|
||||
const result = await copyAndOpen({ text, url: row.sourceHref, copy: copyTextChecked, open: openTab })
|
||||
let next = copyNote(result, row.sourceHref !== null)
|
||||
if (!row.claimedByMe) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user