mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
01d327b502
- Collections is Places now: /places opens "All places", every place of the trips and lists with where it comes from, the same filter row (where from, status, category, order), map bar (search, lock, list toggle) and place sheet as a list; /places/saved and /places/:id are the lists, and the old /collections links still land there. On the phone the same, with its own sheet. A place sheet shows each trip (planned day or trip dates, stay, booking, notes) and each list (status, labels, rating, notes) as one row that opens it. - The rail: a calm "New list" with its plus tile, All places and All saved as views, a "My lists" heading, every name on one edge. Lists can carry one of 24 symbols, shown in their colour in the rail and the editor. - A saved place's row keeps to two lines: its category as an icon before the name, its average vote as a star on the picture. Map pins wear the same star. - The place forms put the category in front of the name as a tile that opens the category list, instead of a row of chips. - All saved gets a subtitle; the import dialog opens centred. - Fixes: a pasted coordinate pair splits from either field of the place form; "more" in All places frees itself when a filter changes mid-load; place names on the trip map and the rating badge follow the reading direction.
193 lines
4.9 KiB
TypeScript
193 lines
4.9 KiB
TypeScript
import type {
|
|
PlacesLibraryDetail,
|
|
PlacesLibraryDetailResponse,
|
|
PlacesLibraryEntry,
|
|
PlacesLibraryInfo,
|
|
PlacesLibraryListDetail,
|
|
PlacesLibraryListOrigin,
|
|
PlacesLibraryPageResponse,
|
|
PlacesLibraryTripDetail,
|
|
PlacesLibraryTripOrigin,
|
|
} from '@trek/shared';
|
|
import { vi } from 'vitest';
|
|
|
|
import type { usePlacesLibrary } from '../../src/components/Collections/usePlacesLibrary';
|
|
|
|
/*
|
|
* Builders for "All places" (PLC-07, PLC-08): an entry with its origins, a page of
|
|
* them, and what each origin keeps of a place. One trip place 42 in "Rome 2026"
|
|
* and one saved place 900 in "Favourites", both the Colosseum, unless told otherwise.
|
|
*/
|
|
|
|
export function tripOrigin(over: Partial<PlacesLibraryTripOrigin> = {}): PlacesLibraryTripOrigin {
|
|
return {
|
|
kind: 'trip',
|
|
trip_id: 5,
|
|
trip_title: 'Rome 2026',
|
|
trip_start: null,
|
|
trip_end: null,
|
|
place_id: 42,
|
|
can_edit: true,
|
|
read_only: false,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function listOrigin(over: Partial<PlacesLibraryListOrigin> = {}): PlacesLibraryListOrigin {
|
|
return {
|
|
kind: 'list',
|
|
collection_id: 9,
|
|
collection_name: 'Favourites',
|
|
collection_place_id: 900,
|
|
status: 'want',
|
|
can_edit: true,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryInfo(over: Partial<PlacesLibraryInfo> = {}): PlacesLibraryInfo {
|
|
return {
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
description: null,
|
|
website: null,
|
|
phone: null,
|
|
image_url: null,
|
|
category: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function tripDetail(over: Partial<PlacesLibraryTripDetail> = {}): PlacesLibraryTripDetail {
|
|
return {
|
|
kind: 'trip',
|
|
place_id: 42,
|
|
info: libraryInfo(),
|
|
notes: null,
|
|
rating: { average: null, count: 0, mine: null },
|
|
days: [],
|
|
has_accommodation: false,
|
|
has_reservation: false,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function listDetail(over: Partial<PlacesLibraryListDetail> = {}): PlacesLibraryListDetail {
|
|
return {
|
|
kind: 'list',
|
|
collection_place_id: 900,
|
|
info: libraryInfo(),
|
|
notes: null,
|
|
labels: [],
|
|
rating: { average: null, count: 0, mine: null },
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryEntry(over: Partial<PlacesLibraryEntry> = {}): PlacesLibraryEntry {
|
|
return {
|
|
key: 'trip:42',
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
category: null,
|
|
image_url: null,
|
|
updated_at: null,
|
|
origins: [tripOrigin()],
|
|
...over,
|
|
};
|
|
}
|
|
|
|
export function libraryPage(
|
|
entries: PlacesLibraryEntry[],
|
|
over: Partial<PlacesLibraryPageResponse> = {}
|
|
): PlacesLibraryPageResponse {
|
|
return {
|
|
entries,
|
|
total: entries.length,
|
|
counts: { all: entries.length, trip: entries.length, list: 0 },
|
|
next_cursor: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** An entry with one detail per origin, in the order of its origins. */
|
|
export function libraryDetail(entry: PlacesLibraryEntry, details: PlacesLibraryDetail[]): PlacesLibraryDetailResponse {
|
|
return { entry, details };
|
|
}
|
|
|
|
/** The Colosseum in the trip and in a list, with what both keep of it. */
|
|
export function bothOrigins(over: Partial<PlacesLibraryEntry> = {}): PlacesLibraryDetailResponse {
|
|
const entry = libraryEntry({ origins: [tripOrigin(), listOrigin()], ...over });
|
|
return libraryDetail(entry, [tripDetail(), listDetail()]);
|
|
}
|
|
|
|
/** What usePlacesLibrary hands a view, for the view tests that mock the hook. */
|
|
export type PlacesLibraryState = ReturnType<typeof usePlacesLibrary>;
|
|
|
|
/** An idle "All places" with nothing loaded, every setter and action a mock. */
|
|
export function libraryState(over: Partial<PlacesLibraryState> = {}): PlacesLibraryState {
|
|
return {
|
|
search: '',
|
|
setSearch: vi.fn(),
|
|
kind: 'all',
|
|
setKind: vi.fn(),
|
|
categoryId: 'all',
|
|
setCategoryId: vi.fn(),
|
|
sort: 'name',
|
|
setSort: vi.fn(),
|
|
status: 'all',
|
|
setStatus: vi.fn(),
|
|
filtered: false,
|
|
resetFilters: vi.fn(),
|
|
entries: [],
|
|
mappable: [],
|
|
total: 0,
|
|
counts: { all: 0, trip: 0, list: 0 },
|
|
hasMore: false,
|
|
loading: false,
|
|
loadingMore: false,
|
|
loadMore: vi.fn(() => Promise.resolve()),
|
|
error: null,
|
|
offline: false,
|
|
reload: vi.fn(),
|
|
selectedKey: null,
|
|
open: vi.fn(),
|
|
show: vi.fn(),
|
|
close: vi.fn(),
|
|
detail: null,
|
|
detailLoading: false,
|
|
cover: null,
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** Three places: two in trips with a position, one saved without. */
|
|
export function threeEntries(): PlacesLibraryEntry[] {
|
|
return [
|
|
libraryEntry({
|
|
key: 'trip:1',
|
|
name: 'Pantheon',
|
|
address: 'Piazza della Rotonda',
|
|
origins: [tripOrigin({ place_id: 1 })],
|
|
}),
|
|
libraryEntry({
|
|
key: 'trip:2',
|
|
name: 'Trevi Fountain',
|
|
address: null,
|
|
origins: [tripOrigin({ place_id: 2 }), listOrigin({ collection_place_id: 20 })],
|
|
}),
|
|
libraryEntry({
|
|
key: 'list:30',
|
|
name: 'Secret garden',
|
|
address: null,
|
|
lat: null,
|
|
lng: null,
|
|
origins: [listOrigin({ collection_place_id: 30, collection_name: 'Wishlist' })],
|
|
}),
|
|
];
|
|
}
|