mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(places): notes, visits, tours, history, tags and location in the place sheet, saved lists on the trip map
Both the desktop sheet and the phone sheet of All places show the place's location as a badge, its notes per list, its visits from trips (hidden without any), linked tours and bookings, its change history and the reader's own tags with a tag filter. A trip map can show the places of linked lists and add one to the trip. All places reloads after a list is added or removed.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type {
|
||||
PlaceActivitiesResponse,
|
||||
PlaceActivityCandidatesResponse,
|
||||
PlaceLibraryActivitiesResponse,
|
||||
PlacesLibraryKind,
|
||||
TripPlaceActivityLinkRequest,
|
||||
} from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
const tripBase = (tripId: number, placeId: number) => `/trips/${tripId}/places/${placeId}/activities`;
|
||||
const savedBase = (collectionPlaceId: number) => `/addons/collections/places/${collectionPlaceId}/activities`;
|
||||
|
||||
/**
|
||||
* PLC-18: the bookings and tours a place is about. A trip place links bookings
|
||||
* and tours of its trip, a saved place tours kept in its list; an entry of All
|
||||
* places reads them over every origin it has. Unlinking takes only the link off.
|
||||
*/
|
||||
export const placeActivitiesApi = {
|
||||
tripPlace: (tripId: number, placeId: number, signal?: AbortSignal): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.get(tripBase(tripId, placeId), { signal }).then((r) => r.data),
|
||||
tripCandidates: (tripId: number, placeId: number, signal?: AbortSignal): Promise<PlaceActivityCandidatesResponse> =>
|
||||
apiClient.get(`${tripBase(tripId, placeId)}/candidates`, { signal }).then((r) => r.data),
|
||||
linkTrip: (tripId: number, placeId: number, body: TripPlaceActivityLinkRequest): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.post(tripBase(tripId, placeId), body).then((r) => r.data),
|
||||
unlinkTripBooking: (tripId: number, placeId: number, reservationId: number): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.delete(`${tripBase(tripId, placeId)}/reservations/${reservationId}`).then((r) => r.data),
|
||||
unlinkTripTour: (tripId: number, placeId: number, tourId: number): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.delete(`${tripBase(tripId, placeId)}/tours/${tourId}`).then((r) => r.data),
|
||||
|
||||
savedPlace: (collectionPlaceId: number, signal?: AbortSignal): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.get(savedBase(collectionPlaceId), { signal }).then((r) => r.data),
|
||||
savedCandidates: (collectionPlaceId: number, signal?: AbortSignal): Promise<PlaceActivityCandidatesResponse> =>
|
||||
apiClient.get(`${savedBase(collectionPlaceId)}/candidates`, { signal }).then((r) => r.data),
|
||||
linkSaved: (collectionPlaceId: number, collectionTourId: number): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.post(savedBase(collectionPlaceId), { collection_tour_id: collectionTourId }).then((r) => r.data),
|
||||
unlinkSaved: (collectionPlaceId: number, collectionTourId: number): Promise<PlaceActivitiesResponse> =>
|
||||
apiClient.delete(`${savedBase(collectionPlaceId)}/tours/${collectionTourId}`).then((r) => r.data),
|
||||
|
||||
libraryEntry: (kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlaceLibraryActivitiesResponse> =>
|
||||
apiClient.get(`/addons/collections/library/places/${kind}/${id}/activities`, { signal }).then((r) => r.data),
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { PlaceHistoryPageResponse, PlaceHistoryQueryInput, PlacesLibraryKind } from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
const base = '/addons/collections/library/places';
|
||||
|
||||
/** PLC-14: what changed in the details of an entry of All places, opened from a trip place or a saved place. */
|
||||
export const placeHistoryApi = {
|
||||
history: (
|
||||
kind: PlacesLibraryKind,
|
||||
id: number,
|
||||
query: PlaceHistoryQueryInput = {},
|
||||
signal?: AbortSignal
|
||||
): Promise<PlaceHistoryPageResponse> =>
|
||||
apiClient.get(`${base}/${kind}/${id}/history`, { params: query, signal }).then((r) => r.data),
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import type {
|
||||
CreateTagRequest,
|
||||
PlacesLibraryBulkTagsRequest,
|
||||
PlacesLibraryBulkTagsResponse,
|
||||
PlacesLibraryEntryTagsRequest,
|
||||
PlacesLibraryEntryTagsResponse,
|
||||
Tag,
|
||||
TagListResponse,
|
||||
UpdateTagRequest,
|
||||
} from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
const base = '/addons/collections/library/places/tags';
|
||||
|
||||
/**
|
||||
* PLC-21: the user's personal tags (the ones /tags keeps) and which entries
|
||||
* of All places carry them. Everything here is the user's own and private.
|
||||
*/
|
||||
export const placeTagsApi = {
|
||||
list: (): Promise<TagListResponse> => apiClient.get('/tags').then((r) => r.data),
|
||||
create: (body: CreateTagRequest): Promise<{ tag: Tag }> =>
|
||||
apiClient.post('/tags', body satisfies CreateTagRequest).then((r) => r.data),
|
||||
update: (id: number, body: UpdateTagRequest): Promise<{ tag: Tag }> =>
|
||||
apiClient.put(`/tags/${id}`, body satisfies UpdateTagRequest).then((r) => r.data),
|
||||
remove: (id: number): Promise<{ success: boolean }> => apiClient.delete(`/tags/${id}`).then((r) => r.data),
|
||||
/** The entry carries exactly these tags from now on. */
|
||||
setForEntry: (body: PlacesLibraryEntryTagsRequest): Promise<PlacesLibraryEntryTagsResponse> =>
|
||||
apiClient.put(base, body satisfies PlacesLibraryEntryTagsRequest).then((r) => r.data),
|
||||
/** Puts tags on several entries and takes others off them. */
|
||||
bulk: (body: PlacesLibraryBulkTagsRequest): Promise<PlacesLibraryBulkTagsResponse> =>
|
||||
apiClient.post(`${base}/bulk`, body satisfies PlacesLibraryBulkTagsRequest).then((r) => r.data),
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
import type {
|
||||
PlaceMediaResponse,
|
||||
PlacesLibraryKind,
|
||||
PlaceVisitsForPlaceResponse,
|
||||
PlaceVisitsListQuery,
|
||||
PlaceVisitsListResponse,
|
||||
PlaceVisitTripVisitedResponse,
|
||||
} from '@trek/shared';
|
||||
import apiClient from './client';
|
||||
|
||||
/**
|
||||
* D7/PLC-10, PLC-19, PLC-20, PLC-23: the visits the server reads from the
|
||||
* trips (nothing to write: a visit comes from the trip's plan), the trip
|
||||
* places visited, and the photos and files of an entry of All places.
|
||||
*/
|
||||
export const placeVisitsApi = {
|
||||
list: (query: PlaceVisitsListQuery = {}, signal?: AbortSignal): Promise<PlaceVisitsListResponse> =>
|
||||
apiClient.get('/place-visits', { params: query, signal }).then((r) => r.data),
|
||||
forPlace: (kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlaceVisitsForPlaceResponse> =>
|
||||
apiClient.get('/place-visits/place', { params: { kind, id }, signal }).then((r) => r.data),
|
||||
tripVisited: (tripId: number, signal?: AbortSignal): Promise<PlaceVisitTripVisitedResponse> =>
|
||||
apiClient.get(`/trips/${tripId}/place-visits/mine`, { signal }).then((r) => r.data),
|
||||
media: (kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlaceMediaResponse> =>
|
||||
apiClient.get(`/addons/collections/library/places/${kind}/${id}/media`, { signal }).then((r) => r.data),
|
||||
};
|
||||
@@ -8,10 +8,18 @@ import apiClient from './client';
|
||||
|
||||
const base = '/addons/collections/library/places';
|
||||
|
||||
/** The query as the server reads it: a tag filter (PLC-21) as its ids joined by commas, not `tag_ids[]=`. */
|
||||
function queryParams(query: PlacesLibraryQueryInput): Record<string, unknown> {
|
||||
const { tag_ids: tagIds, ...rest } = query;
|
||||
if (tagIds === undefined) return rest;
|
||||
const joined = Array.isArray(tagIds) ? tagIds.join(',') : tagIds;
|
||||
return joined === '' ? rest : { ...rest, tag_ids: joined };
|
||||
}
|
||||
|
||||
/** PLC-07/PLC-08 "All places": one page of entries, and one entry by the trip place or saved place it was opened from. */
|
||||
export const placesLibraryApi = {
|
||||
list: (query: PlacesLibraryQueryInput = {}, signal?: AbortSignal): Promise<PlacesLibraryPageResponse> =>
|
||||
apiClient.get(base, { params: query, signal }).then((r) => r.data),
|
||||
apiClient.get(base, { params: queryParams(query), signal }).then((r) => r.data),
|
||||
detail: (kind: PlacesLibraryKind, id: number, signal?: AbortSignal): Promise<PlacesLibraryDetailResponse> =>
|
||||
apiClient.get(`${base}/${kind}/${id}`, { signal }).then((r) => r.data),
|
||||
};
|
||||
|
||||
@@ -53,6 +53,9 @@ export const HANDLED_OUTSIDE_TRIP_STORE = [
|
||||
// Linked lists (PLC-15/PLC-16): store/tripCollectionsStore (watchTripCollections) reads the
|
||||
// trip's linked lists and map layer again; content-free because each member's answer differs.
|
||||
'tripCollections:changed',
|
||||
// Place activities (PLC-18): store/placeActivitiesStore (watchPlaceActivities) reads the
|
||||
// bookings and tours of the held trip place, and the All places entries it is an origin of, again.
|
||||
'placeActivities:changed',
|
||||
// components/Roadtrip/useDayBoundaries reloads the shared boundaries.
|
||||
'roadtripBoundary:changed',
|
||||
// In-app notifications: hooks/useInAppNotificationListener, which also keeps
|
||||
|
||||
Reference in New Issue
Block a user