mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
feat(tours): the paddle checklist through the offline core on the client
PAD-06 and PAD-09 on the client's data side. A tour's cached row keeps its checklist beside its provenance, written through one cache helper by the repository and the queue replay, which also keeps provenance an answer lacks. The checklist is read for the bench the list shows and served from the cache while its revision matches. Decisions made offline, or behind a queued write of the same tour, change the cached checklist and bench at once under a local revision and replay with their idempotency key; a route written offline marks the checklist stale until the server judged it. The obstacle store learns a camera focus: a click in the rail moves the camera onto an obstacle and the other parts of its lock, the newest of such a focus and a picked search result wins, and a selected lock lights up whole on both maps. The checklist hook and its model hold the logic the cards will show.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// A tour answer written to the cache (PAD-06): its control points, and where it
|
||||
// came from and its checklist kept from the cached row when the answer lacks them.
|
||||
import type { TourListItem } from '@trek/shared';
|
||||
import 'fake-indexeddb/auto';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { obstacleCheck } from '../../tests/helpers/paddleCheck';
|
||||
import { cacheTourAnswer } from './cacheTour';
|
||||
import { clearAll, offlineDb } from './offlineDb';
|
||||
|
||||
function tour(overrides: Partial<TourListItem> = {}): TourListItem {
|
||||
return {
|
||||
place_id: 40,
|
||||
name: 'Regen',
|
||||
tour_type: 'kayak',
|
||||
distance: 8,
|
||||
elevation_gain: null,
|
||||
elevation_loss: null,
|
||||
duration: 120,
|
||||
difficulty: null,
|
||||
wanderer_ref: null,
|
||||
match_confidence: 1,
|
||||
max_hiking_difficulty: null,
|
||||
planned: false,
|
||||
caution: false,
|
||||
has_waypoints: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const waypoints = [
|
||||
{ lat: 49.2, lng: 12, role: 'start' as const, sequence: 0 },
|
||||
{ lat: 49.2, lng: 12.01, role: 'end' as const, sequence: 1 },
|
||||
];
|
||||
const provenance = {
|
||||
origin: 'trek' as const,
|
||||
createdAt: null,
|
||||
source: null,
|
||||
derivedFrom: null,
|
||||
plannedOver: false,
|
||||
editedLocally: null,
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
await clearAll();
|
||||
});
|
||||
|
||||
describe('cacheTourAnswer', () => {
|
||||
it('CT-001: writes the tour with its trip, control points, provenance and checklist', async () => {
|
||||
const check = obstacleCheck();
|
||||
const row = await cacheTourAnswer(3, { tour: tour(), waypoints, provenance, obstacle_check: check });
|
||||
expect(row).toMatchObject({ place_id: 40, trip_id: 3, waypoints, provenance, obstacle_check: check });
|
||||
expect(await offlineDb.tours.get(40)).toEqual(row);
|
||||
});
|
||||
|
||||
it('CT-002: an answer without provenance or checklist keeps the cached ones', async () => {
|
||||
const check = obstacleCheck();
|
||||
await cacheTourAnswer(3, { tour: tour(), waypoints, provenance, obstacle_check: check });
|
||||
const row = await cacheTourAnswer(3, { tour: tour({ name: 'Regen again' }), waypoints });
|
||||
expect(row).toMatchObject({ name: 'Regen again', provenance, obstacle_check: check });
|
||||
});
|
||||
|
||||
it('CT-003: a tour that is no paddle tour any more drops its checklist', async () => {
|
||||
await cacheTourAnswer(3, { tour: tour(), waypoints, obstacle_check: obstacleCheck() });
|
||||
const row = await cacheTourAnswer(3, { tour: tour({ tour_type: 'hike' }), waypoints });
|
||||
expect(row).not.toHaveProperty('obstacle_check');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { TourCreateResponse } from '@trek/shared';
|
||||
import { offlineDb, type CachedTour } from './offlineDb';
|
||||
|
||||
/**
|
||||
* A tour as the server answered it, written to the cache with its control
|
||||
* points. Where it came from and a paddle tour's checklist are kept from the
|
||||
* row already there when the answer carries none, so a write answered
|
||||
* without them does not lose them. Safe inside a Dexie transaction that
|
||||
* holds the tours table.
|
||||
*/
|
||||
export async function cacheTourAnswer(tripId: number, answer: TourCreateResponse): Promise<CachedTour> {
|
||||
const previous = await offlineDb.tours.get(answer.tour.place_id);
|
||||
const provenance = answer.provenance ?? previous?.provenance;
|
||||
// Only a paddle tour has a checklist; a tour that stopped being one drops it.
|
||||
const check = answer.tour.tour_type === 'kayak' ? (answer.obstacle_check ?? previous?.obstacle_check) : undefined;
|
||||
const row: CachedTour = {
|
||||
...answer.tour,
|
||||
trip_id: tripId,
|
||||
waypoints: answer.waypoints,
|
||||
...(provenance ? { provenance } : {}),
|
||||
...(check ? { obstacle_check: check } : {}),
|
||||
};
|
||||
await offlineDb.tours.put(row);
|
||||
return row;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Ferrata, RoadtripPreferences, TourListItem, TourProvenance, TourWaypoint } from '@trek/shared';
|
||||
import type { Ferrata, RoadtripPreferences, TourListItem, TourObstacleCheck, TourProvenance, TourWaypoint } from '@trek/shared';
|
||||
import Dexie, { type Table } from 'dexie';
|
||||
import type { Trip, Day, Place, PackingItem, TodoItem, BudgetItem, Reservation, TripFile, Accommodation, TripMember, Tag, Category } from '../types';
|
||||
|
||||
@@ -17,6 +17,8 @@ export interface CachedTour extends TourListItem {
|
||||
waypoints?: TourWaypoint[];
|
||||
/** Where the tour came from, as its detail last said; kept across list refreshes, since it does not change. */
|
||||
provenance?: TourProvenance;
|
||||
/** A paddle tour's obstacle checklist as its detail last said; its revision tells whether the list's bench still matches. */
|
||||
obstacle_check?: TourObstacleCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,6 +473,7 @@ export async function replaceTripTours(tripId: number, tours: TourListItem[]): P
|
||||
trip_id: tripId,
|
||||
...(sameRoute && previous.waypoints ? { waypoints: previous.waypoints } : {}),
|
||||
...(previous?.provenance ? { provenance: previous.provenance } : {}),
|
||||
...(previous?.obstacle_check ? { obstacle_check: previous.obstacle_check } : {}),
|
||||
};
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user