fix: file viewers blocked on mobile — open blank window before async fetch
Mobile browsers block window.open() after async operations. Changed all file viewers to open a blank window synchronously in the click handler, then set location.href after fetch completes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -975,18 +975,21 @@ export default function InvoiceDetail() {
|
||||
|
||||
// ─── Edit mode: PDF export ───
|
||||
const handleViewPdf = async (_lang = "cs") => {
|
||||
const newWindow = window.open("", "_blank");
|
||||
setPdfLoading(true);
|
||||
try {
|
||||
const response = await apiFetch(`${API_BASE}/invoices/${id}/file`);
|
||||
if (!response.ok) {
|
||||
newWindow?.close();
|
||||
alert.error("PDF soubor nenalezen — uložte fakturu pro vygenerování");
|
||||
return;
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, "_blank");
|
||||
if (newWindow) newWindow.location.href = url;
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
} catch {
|
||||
newWindow?.close();
|
||||
alert.error("Chyba připojení");
|
||||
} finally {
|
||||
setPdfLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user