mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(places): one place view for All places and the lists
The desktop dialog and the phone sheet of a place show its overview, notes, tours and bookings, photos and files and its history in tabs, with the tags of each list and trip, a markdown notes editor, uploads and the place picture. The rating bar of All places is the rating row the lists show, with its voters, and votes once for every copy. All places filters by a lowest rating and sorts by it, and the edit form changes the first copy the reader may edit, which the server carries to the others.
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
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),
|
||||
};
|
||||
@@ -1,19 +1,24 @@
|
||||
import type {
|
||||
PlacesLibraryDetailResponse,
|
||||
PlacesLibraryKind,
|
||||
PlacesLibraryPageResponse,
|
||||
PlacesLibraryQueryInput,
|
||||
import {
|
||||
joinLibraryTagNames,
|
||||
type PlacesLibraryDetailResponse,
|
||||
type PlacesLibraryKind,
|
||||
type PlacesLibraryPageResponse,
|
||||
type PlacesLibraryQueryInput,
|
||||
type PlacesLibraryRateResponse,
|
||||
} from '@trek/shared';
|
||||
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[]=`. */
|
||||
/**
|
||||
* The query as the server reads it: a tag filter (PLC-21) as its names joined by commas, a comma
|
||||
* inside a name escaped (`joinLibraryTagNames`), not `tags[]=`.
|
||||
*/
|
||||
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 };
|
||||
const { tags, ...rest } = query;
|
||||
if (tags === undefined) return rest;
|
||||
const joined = Array.isArray(tags) ? joinLibraryTagNames(tags) : tags;
|
||||
return joined === '' ? rest : { ...rest, tags: 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. */
|
||||
@@ -22,4 +27,9 @@ export const placesLibraryApi = {
|
||||
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),
|
||||
/** The reader's vote on an entry, on every copy of it they may vote on; null takes it back. */
|
||||
rate: (key: string, rating: number | null): Promise<PlacesLibraryRateResponse> =>
|
||||
rating === null
|
||||
? apiClient.delete(`${base}/rating`, { params: { key } }).then((r) => r.data)
|
||||
: apiClient.put(`${base}/rating`, { key, rating }).then((r) => r.data),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user