mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
f8e51cb83d
An iPhone or iPad running TREK from the Home Screen ignores print(), in the page and in an iframe alike, so "Save as PDF" in the preview did nothing there. Mobile Safari prints the same preview fine. In the installed iOS app the preview now shows "Open in Safari" in place of the dead button, with a line saying why. The link opens the trip with ?export=pdf, and both shells open their export dialog or sheet for it, so the PDF is one tap away once Safari is up. The parameter is dropped once read and survives the login redirect. Everywhere else the preview prints as before. The preview overlay moves out of TripPDF.tsx into pdfPreview.ts, which TripPDF had no room left for under lint:size, and its backdrop and stacking now use the --overlay and --z-modal tokens.
29 lines
961 B
TypeScript
29 lines
961 B
TypeScript
import { useEffect, useEffectEvent } from 'react';
|
|
import { useSearchParams } from 'react-router';
|
|
|
|
import { EXPORT_PARAM, EXPORT_PDF } from '../utils/pdfSafariHandoff';
|
|
|
|
/**
|
|
* Opens the trip's export when the address asks for it (`?export=pdf`), the way
|
|
* the iOS Home Screen app hands a PDF over to Safari. The parameter is dropped
|
|
* once read, so a reload or a copied link does not open the dialog again.
|
|
*/
|
|
export function useExportDeepLink(openExport: () => void): void {
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
const requested = searchParams.get(EXPORT_PARAM) === EXPORT_PDF;
|
|
// The shells pass a fresh closure on every render; the request is answered once.
|
|
const open = useEffectEvent(openExport);
|
|
|
|
useEffect(() => {
|
|
if (!requested) return;
|
|
open();
|
|
setSearchParams(
|
|
(p) => {
|
|
p.delete(EXPORT_PARAM);
|
|
return p;
|
|
},
|
|
{ replace: true }
|
|
);
|
|
}, [requested, setSearchParams]);
|
|
}
|