mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +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,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