mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
9956c58dd5
- The trip's addon list is read through tripAddonsRepo into tripAddonsStore (per account and trip, kept in Dexie version 16 for offline), refreshed when the connection returns and live on tripAddons:changed. - The planner's tabs, dock, rail and deep links, the cost, tour and list readers, the PDF export, the share link options, the widgets and the watch follow the trip instead of the instance switch. - Trip settings gets an Addons area for the owner, on the desktop dialog and the phone sheet, on one useTripAddonRows hook: each trip addon with its switch, marked "This trip only" while it differs from the instance. Switching back to the instance's value drops the trip's choice. Switching needs a connection.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import type { TripAddon } from '@trek/shared';
|
|
|
|
/**
|
|
* Whether an addon applies to one trip.
|
|
*
|
|
* The trip's own list says it for every trip addon (lists, costs, files, collab,
|
|
* road trip, tours), the owner's choice or the instance switch, whichever the
|
|
* server worked out. An addon the list does not name (an integration such as
|
|
* Dawarich, or any addon while the list is not known yet) follows the
|
|
* instance switch the caller passes in.
|
|
*/
|
|
export function tripAddonEnabled(
|
|
tripAddons: readonly TripAddon[] | null | undefined,
|
|
addonId: string,
|
|
instanceEnabled: boolean
|
|
): boolean {
|
|
const own = tripAddons?.find((addon) => addon.id === addonId);
|
|
return own ? own.enabled : instanceEnabled;
|
|
}
|
|
|
|
/** The trip addon a core trip tab belongs to; a plugin page that replaces the tab follows it. */
|
|
const TRIP_TAB_ADDON: Readonly<Record<string, string>> = {
|
|
listen: 'packing',
|
|
finanzplan: 'budget',
|
|
dateien: 'documents',
|
|
collab: 'collab',
|
|
};
|
|
|
|
/**
|
|
* Whether a plugin's trip page shows on a trip. A page that replaces core tabs
|
|
* stands in for them, so it shows while the addon of at least one of those tabs
|
|
* is on for the trip; a page that replaces none (or only tabs no addon owns)
|
|
* always shows.
|
|
*/
|
|
export function pluginPageShown(
|
|
replaces: readonly string[] | undefined,
|
|
addonOn: (addonId: string) => boolean
|
|
): boolean {
|
|
const owned = (replaces ?? []).flatMap((tab) => (TRIP_TAB_ADDON[tab] ? [TRIP_TAB_ADDON[tab]] : []));
|
|
return owned.length === 0 || owned.some(addonOn);
|
|
}
|