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:
Maurice
2026-11-29 23:36:43 +00:00
parent 783c98f41e
commit d758f4c592
78 changed files with 5604 additions and 2797 deletions
+5 -3
View File
@@ -19,9 +19,11 @@ import type {
/** A pending invitation the current user has received (derived server-side). */
export type IncomingCollectionInvite = CollectionListResponse['incomingInvites'][number]
/** What a copy into a trip takes along besides the places (D9): left out, neither notes nor tags. */
/** What comes along into the trip: the notes, the list's tags, and (PLC-21) the personal tags chosen to share. */
type CopyToTripCarry = Pick<CollectionCopyToTripRequest, 'include_notes' | 'tag_ids' | 'personal_tag_ids'>
/**
* What a copy into a trip takes along besides the places (D9), only what the reader picked:
* the notes, the place's tags (`tag_ids`) and the list's own tags, its labels (`label_ids`, PLC-21).
*/
type CopyToTripCarry = Pick<CollectionCopyToTripRequest, 'include_notes' | 'tag_ids' | 'label_ids'>
/** Sentinel id for the client-side "All saved" union pseudo-list. */
export const ALL_SAVED = 'all' as const
-90
View File
@@ -1,90 +0,0 @@
import type { PlacesLibraryBulkTagsRequest, PlacesLibraryEntry, Tag } from '@trek/shared';
import { create } from 'zustand';
import { addListener, removeListener } from '../api/websocket';
import { placeTagsRepo } from '../repo/placeTagsRepo';
/**
* PLC-21: the signed-in user's personal tags, as the tag picker and the tag
* filter of All places offer them, by name. Online only, like the repo. The
* assignments themselves are not kept here: an entry carries its own tags,
* and a change answers the entries as they are now, for the caller to put
* where it shows them. A `tags:changed` push (another tab or device changed
* the tags) reads the list again.
*/
interface PlaceTagsState {
tags: Tag[];
loaded: boolean;
/** Reads the tags again. Online only; throws when offline or refused. */
load: () => Promise<Tag[]>;
/** The user's tag of that name (case ignored), made now when there is none yet. */
create: (name: string, color?: string) => Promise<Tag>;
update: (id: number, changes: { name?: string; color?: string }) => Promise<Tag>;
/** Deletes the tag; it comes off every place that carried it. */
remove: (id: number) => Promise<void>;
/** The entry carries exactly these tags from now on; answers the entry, null once out of reach. */
setForEntry: (key: string, tagIds: number[]) => Promise<PlacesLibraryEntry | null>;
/** Puts tags on several entries and takes others off; answers the entries. */
bulk: (body: PlacesLibraryBulkTagsRequest) => Promise<PlacesLibraryEntry[]>;
}
const byName = (a: Tag, b: Tag) => String(a.name).localeCompare(String(b.name)) || a.id - b.id;
/** The list with `tag` in it, once, in name order. */
function withTag(tags: Tag[], tag: Tag): Tag[] {
return [...tags.filter((other) => other.id !== tag.id), tag].sort(byName);
}
export const usePlaceTagsStore = create<PlaceTagsState>((set) => ({
tags: [],
loaded: false,
async load() {
const tags = [...(await placeTagsRepo.list())].sort(byName);
set({ tags, loaded: true });
return tags;
},
async create(name, color) {
const tag = await placeTagsRepo.create(name, color);
set((state) => ({ tags: withTag(state.tags, tag) }));
return tag;
},
async update(id, changes) {
const tag = await placeTagsRepo.update(id, changes);
set((state) => ({ tags: withTag(state.tags, tag) }));
return tag;
},
async remove(id) {
await placeTagsRepo.remove(id);
set((state) => ({ tags: state.tags.filter((tag) => tag.id !== id) }));
},
async setForEntry(key, tagIds) {
return await placeTagsRepo.setForEntry(key, tagIds);
},
async bulk(body) {
return await placeTagsRepo.bulk(body);
},
}));
/**
* Reads the tags again on a `tags:changed` push while the store has been
* loaded once. Returns the unsubscribe.
*/
export function subscribePlaceTags(): () => void {
const onEvent = (event: Record<string, unknown>) => {
if (event?.type !== 'tags:changed') return;
const store = usePlaceTagsStore.getState();
if (!store.loaded) return;
void store.load().catch(() => {
// Offline or refused: the last list stays until the next read.
return undefined;
});
};
addListener(onEvent);
return () => removeListener(onEvent);
}