Files
TREK/client/src/utils/donations.ts
T
Maurice bcdcd69a64 feat(notices): 5.2.0 release modal and Patreon for monthly support
The release modal now shows 5.2.0: booking mails that land in the trip,
live flight status and the new trip PDF, each with its own drawn card,
and links the 5.2.0 release notes. The maintainer note and the support
block are rewritten, shorter and without the sponsor wording.

Patreon joins Buy Me a Coffee and Ko-fi as the monthly way to support
TREK: a full-width button in the release and thank-you notices (a new
optional tertiaryCta on the notice contract), a tile in About and in the
admin GitHub panel on desktop and phone, the README badges and
FUNDING.yml. Like the other donation links it stays hidden inside the
native apps.
2026-11-23 21:15:54 +01:00

43 lines
1.5 KiB
TypeScript

import { isNativeApp } from '../native/platform';
/** Where the project takes donations. */
const DONATION_HOSTS = ['ko-fi.com', 'buymeacoffee.com', 'patreon.com'];
/** Whether `href` points at one of the project's donation pages. */
export function isDonationLink(href: string | undefined): boolean {
if (!href) return false;
let host: string;
try {
host = new URL(href).hostname.toLowerCase();
} catch {
return false;
}
return DONATION_HOSTS.some((d) => host === d || host.endsWith(`.${d}`));
}
/**
* Whether the donation links may show. Not inside the iOS and Android apps:
* the store rules on payments (Apple 3.1.1, Google Play's Payments policy)
* allow no link to an outside payment page there. A browser keeps them.
*/
export function donationsShown(): boolean {
return !isNativeApp();
}
/** `links` without the donation pages inside the native apps, unchanged anywhere else. */
export function withoutDonationsInApp<T extends { href: string }>(links: T[]): T[] {
return donationsShown() ? links : links.filter((link) => !isDonationLink(link.href));
}
/** A notice button: a link or a navigation carries an href, an action does not. */
type NoticeButton = { kind: string; href?: string } | null | undefined;
/** Whether a system notice asks for a donation through one of its buttons. */
export function noticeAsksForDonation(notice: {
cta?: NoticeButton;
secondaryCta?: NoticeButton;
tertiaryCta?: NoticeButton;
}): boolean {
return [notice.cta, notice.secondaryCta, notice.tertiaryCta].some((cta) => isDonationLink(cta?.href));
}