mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
fix(pdf): hand the trip PDF to Safari from the iOS Home Screen app
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.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* FE-PDFSAFARI-001: the link the iOS Home Screen app hands to Safari.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { EXPORT_PARAM, EXPORT_PDF, pdfExportUrl } from './pdfSafariHandoff';
|
||||
|
||||
describe('pdfExportUrl', () => {
|
||||
it('FE-PDFSAFARI-001: is the absolute trip address with the export asked for', () => {
|
||||
const url = new URL(pdfExportUrl(42));
|
||||
expect(url.origin).toBe(window.location.origin);
|
||||
expect(url.pathname).toBe('/trips/42');
|
||||
expect(url.searchParams.get(EXPORT_PARAM)).toBe(EXPORT_PDF);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* An iPhone or iPad ignores print() in an app added to the Home Screen, in the
|
||||
* page and in an iframe alike, so the trip PDF cannot be saved from there. Safari
|
||||
* can print it. This is the link that hands the export over: it opens the trip in
|
||||
* Safari with the export dialog already up.
|
||||
*/
|
||||
|
||||
export const EXPORT_PARAM = 'export';
|
||||
export const EXPORT_PDF = 'pdf';
|
||||
|
||||
/** The trip, opened with its export dialog showing. Absolute, since it leaves the installed app. */
|
||||
export function pdfExportUrl(tripId: number): string {
|
||||
return `${window.location.origin}/trips/${tripId}?${EXPORT_PARAM}=${EXPORT_PDF}`;
|
||||
}
|
||||
Reference in New Issue
Block a user