mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
bacc6a29a7
All places offers the pairs that look like one place: both sides side by side with what differs marked, "keep this one" to group them as one place of the user's own (undo right after), and "not the same place" to set a pair aside for good. Desktop dialog and phone sheet share usePlaceDuplicates; every locale has the new strings. What the last dev run flagged on the client: - Tailwind's Prettier plugin had trimmed the leading space of conditional class names (col-filter-btn, col-lrow sel, col-split map-full, col-detail docked), so the filter row and the open row lost their styling; those classes are now joined so the formatter cannot glue them. - The dock position lives in one helper for the lists and All places, which moves the measured-position markers there instead of adding new ones. - usePlacesLibrary is split into filters, pages, detail and cover hooks that derive their loading state instead of setting it inside effects; the big sheets and views are cut into parts under the complexity limit, dynamic icons go through createElement, originName moves out of a component file. - formatRange is guarded like in the packing export, the cover lookup skips places without a position. - Tests follow the rename to Places, the category icon, the default list icon and the new trip collections store; react-hooks/refs is lowered to the count the run measured. - The rating on a place is a round badge again, in the list and on the map.
225 lines
5.9 KiB
TypeScript
225 lines
5.9 KiB
TypeScript
import type {
|
|
PlacesLibraryDetail,
|
|
PlacesLibraryDetailResponse,
|
|
PlacesLibraryDuplicate,
|
|
PlacesLibraryDuplicateSide,
|
|
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' })],
|
|
}),
|
|
];
|
|
}
|
|
|
|
/** One side of a suggested pair: the Colosseum as one trip place, with its provider ids unset. */
|
|
export function duplicateSide(over: Partial<PlacesLibraryDuplicateSide> = {}): PlacesLibraryDuplicateSide {
|
|
return {
|
|
key: 'trip:42',
|
|
identity_id: null,
|
|
name: 'Colosseum',
|
|
address: 'Piazza del Colosseo',
|
|
lat: 41.89,
|
|
lng: 12.49,
|
|
category: null,
|
|
google_place_id: null,
|
|
google_ftid: null,
|
|
osm_id: null,
|
|
origins: [tripOrigin()],
|
|
...over,
|
|
};
|
|
}
|
|
|
|
/** A suggested pair: the trip's Colosseum and a saved "Colosseo", the same name nearby, mergeable. */
|
|
export function duplicatePair(over: Partial<PlacesLibraryDuplicate> = {}): PlacesLibraryDuplicate {
|
|
return {
|
|
a: duplicateSide(),
|
|
b: duplicateSide({ key: 'list:900', name: 'Colosseo', origins: [listOrigin()] }),
|
|
reasons: ['name_nearby'],
|
|
differing: ['name'],
|
|
can_merge: true,
|
|
...over,
|
|
};
|
|
}
|