mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +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.
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { tripAddonsResponseSchema, tripAddonUpdateRequestSchema } from '@trek/shared';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { contractHandler } from '../contract';
|
|
|
|
export const addonHandlers = [
|
|
// Whose AI model reads images: off unless a test says otherwise, so no photo picker shows by default.
|
|
http.get('/api/llm/capabilities', () => HttpResponse.json({ images: false })),
|
|
http.get('/api/addons', () => {
|
|
return HttpResponse.json({
|
|
bagTracking: false,
|
|
addons: [
|
|
{ id: 'vacay', name: 'Vacay', type: 'feature', icon: 'calendar', enabled: true },
|
|
{ id: 'atlas', name: 'Atlas', type: 'feature', icon: 'map', enabled: true },
|
|
],
|
|
});
|
|
}),
|
|
// A trip that names no addon of its own: every addon follows the instance switch, as before per-trip addons.
|
|
contractHandler('get', '/api/trips/:tripId/addons', { response: tripAddonsResponseSchema }, ({ params }) => ({
|
|
tripId: Number(params.tripId),
|
|
addons: [],
|
|
})),
|
|
contractHandler(
|
|
'put',
|
|
'/api/trips/:tripId/addons/:addonId',
|
|
{ request: tripAddonUpdateRequestSchema, response: tripAddonsResponseSchema },
|
|
({ params, body }) => ({
|
|
tripId: Number(params.tripId),
|
|
addons: [
|
|
{
|
|
id: String(params.addonId),
|
|
name: String(params.addonId),
|
|
icon: null,
|
|
enabled: body.enabled ?? true,
|
|
instanceEnabled: true,
|
|
overridden: body.enabled !== null,
|
|
},
|
|
],
|
|
})
|
|
),
|
|
];
|