mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
feat(places): tags on places, owned by the trip
A place keeps its one category, which decides its marker, and can now carry any number of tags as extra labels to filter by. - Tags belong to the trip (tags.trip_id): every member sees the same list and whoever may edit the trip's places adds, renames and deletes. Personal tags stay what they were. - The place form picks them on desktop and mobile through one shared hook, usePlaceTags, and can add a new tag to the trip on the spot. - The existing category filter of the places list lists the tags as well. - Tags show on the place (inspector pills, phone place sheet); the marker is untouched. - MCP: create_place, create_and_assign_place and update_place take `tags`, and list/create/update/delete_trip_tag manage a trip's tags. - /api/trips/:tripId/tags and the tripTags:changed event keep every client of the trip in step.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { Tag } from '@trek/shared';
|
||||
import { offlineDb } from './offlineDb';
|
||||
|
||||
/** The trip's tags as the server last listed them; none while the device never read them. */
|
||||
export async function cachedTripTags(tripId: number): Promise<Tag[]> {
|
||||
return (await offlineDb.tripTags.get(tripId))?.tags ?? [];
|
||||
}
|
||||
|
||||
/** Keeps the trip's tags as the server listed them. */
|
||||
export async function cacheTripTags(tripId: number, tags: Tag[]): Promise<void> {
|
||||
await offlineDb.tripTags.put({ tripId, tags });
|
||||
}
|
||||
@@ -70,6 +70,16 @@ interface CachedTourDraft {
|
||||
draft: TourDraft;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags a trip owns, as the server last listed them: one row per trip, so the
|
||||
* place form and the category filter still offer them offline. Not the `tags`
|
||||
* table, which holds the signed-in user's personal ones.
|
||||
*/
|
||||
interface CachedTripTags {
|
||||
tripId: number;
|
||||
tags: Tag[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A road route as the router answered it, kept on the device so a trip opens
|
||||
* with its roads drawn instead of asking the router for every leg again (#2794).
|
||||
@@ -293,6 +303,7 @@ export class TrekOfflineDb extends Dexie {
|
||||
tourStationVisits!: Table<CachedTourStationVisit, [number, string]>;
|
||||
tourDrafts!: Table<CachedTourDraft, number>;
|
||||
routeCache!: Table<CachedRoute, string>;
|
||||
tripTags!: Table<CachedTripTags, number>;
|
||||
|
||||
constructor(name: string = ANON_DB_NAME) {
|
||||
super(name);
|
||||
@@ -385,6 +396,10 @@ export class TrekOfflineDb extends Dexie {
|
||||
// whole route shown opens drawn instead of re-routing every leg (#2794). Not per
|
||||
// trip: the same waypoints are the same road in any trip; `savedAt` to prune.
|
||||
this.version(14).stores({ routeCache: 'key, savedAt' });
|
||||
|
||||
// v15: the tags a trip owns, one list per trip, so they are offered offline
|
||||
// and go with the trip.
|
||||
this.version(15).stores({ tripTags: 'tripId' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,10 +701,12 @@ export async function clearTripData(tripId: number): Promise<void> {
|
||||
offlineDb.ferrataTiles,
|
||||
offlineDb.tourStationVisits,
|
||||
offlineDb.tourDrafts,
|
||||
offlineDb.tripTags,
|
||||
],
|
||||
async () => {
|
||||
await offlineDb.roadtripPreferences.delete(tripId);
|
||||
await offlineDb.tourDrafts.delete(tripId);
|
||||
await offlineDb.tripTags.delete(tripId);
|
||||
await offlineDb.budgetSettlements.delete(tripId);
|
||||
await offlineDb.days.where('trip_id').equals(tripId).delete();
|
||||
await offlineDb.places.where('trip_id').equals(tripId).delete();
|
||||
|
||||
Reference in New Issue
Block a user