diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json index 875dc8d94..a475e59b5 100644 --- a/client/scripts/eslint-baseline.json +++ b/client/scripts/eslint-baseline.json @@ -8,7 +8,7 @@ "trek/no-swallowed-catch": 124, "max-params": 31, "trek/store-without-selector": 65, - "react-hooks/refs": 391, + "react-hooks/refs": 389, "react-hooks/set-state-in-effect": 188, "@typescript-eslint/no-floating-promises": 162, "react-hooks/exhaustive-deps": 112, diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index dc7819c3b..fb9c0debd 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -68,7 +68,7 @@ "components/Map/locationMarkerMapbox.ts": 2, "components/Map/placePopup.ts": 6, "components/Map/poiCategories.ts": 7, - "components/Map/ratingBadge.ts": 2, + "components/Map/ratingBadge.ts": 1, "components/Map/reservationsMapbox.ts": 1, "components/Map/switcherRow.ts": 1, "components/Packing/PackingListPanelBagModal.tsx": 2, diff --git a/client/src/components/Collections/libraryPairs.ts b/client/src/components/Collections/libraryPairs.ts index 461ee2e7e..48e1d8dd0 100644 --- a/client/src/components/Collections/libraryPairs.ts +++ b/client/src/components/Collections/libraryPairs.ts @@ -23,6 +23,6 @@ export function originPairs(data: PlacesLibraryDetailResponse | null): { return { trips: pairs.filter((p): p is TripPair => p.origin.kind === 'trip' && p.detail.kind === 'trip'), lists: pairs.filter((p): p is ListPair => p.origin.kind === 'list' && p.detail.kind === 'list'), - description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()), + description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()) ?? undefined, }; } diff --git a/client/src/components/Collections/usePlaceDuplicates.test.ts b/client/src/components/Collections/usePlaceDuplicates.test.ts index 6f2c51b87..0c29fdb41 100644 --- a/client/src/components/Collections/usePlaceDuplicates.test.ts +++ b/client/src/components/Collections/usePlaceDuplicates.test.ts @@ -1,13 +1,20 @@ // FE-COMP-PLACEDUPES-001 to FE-COMP-PLACEDUPES-019: the logic behind the duplicates dialog and sheet. import { act, renderHook, waitFor } from '@testing-library/react'; import type { PlacesLibraryDuplicate } from '@trek/shared'; -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { duplicatePair, duplicateSide } from '../../../tests/helpers/placesLibrary'; import { OnlineOnlyError } from '../../repo/onlineOnly'; import { placeIdentitiesRepo } from '../../repo/placeIdentitiesRepo'; import { pairKey, usePlaceDuplicates } from './usePlaceDuplicates'; +// The toasts the hook shows, read through a module mock rather than the window hook. +const toastError = vi.hoisted(() => vi.fn()); +vi.mock('../shared/Toast', () => { + const toast = { error: toastError, success: vi.fn(), warning: vi.fn(), info: vi.fn() }; + return { useToast: () => toast }; +}); + vi.mock('../../repo/placeIdentitiesRepo', () => ({ placeIdentitiesRepo: { duplicates: vi.fn(), @@ -31,8 +38,6 @@ const OTHER_PAIR = duplicatePair({ b: duplicateSide({ key: 'trip:8', name: 'Pantheon Rome' }), }); -let addToast: ReturnType; - function page(pairs: PlacesLibraryDuplicate[], next_cursor: string | null = null) { return { duplicates: pairs, next_cursor }; } @@ -55,12 +60,6 @@ async function loaded(pairs: PlacesLibraryDuplicate[] = [PAIR, OTHER_PAIR], next beforeEach(() => { vi.clearAllMocks(); - addToast = vi.fn(); - window.__addToast = addToast as unknown as typeof window.__addToast; -}); - -afterEach(() => { - delete window.__addToast; }); describe('pairKey', () => { @@ -111,7 +110,7 @@ describe('usePlaceDuplicates', () => { const { result } = setup(); await waitFor(() => expect(result.current.loading).toBe(false)); expect(result.current.pairs).toEqual([]); - expect(addToast).not.toHaveBeenCalled(); + expect(toastError).not.toHaveBeenCalled(); }); it('FE-COMP-PLACEDUPES-007: any other load failure empties the list and says so', async () => { @@ -119,14 +118,14 @@ describe('usePlaceDuplicates', () => { const { result } = setup(); await waitFor(() => expect(result.current.loading).toBe(false)); expect(result.current.pairs).toEqual([]); - expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined); + expect(toastError).toHaveBeenCalledWith('common.error'); }); it('FE-COMP-PLACEDUPES-008: the server message is shown when the load is refused with one', async () => { duplicates.mockRejectedValue({ response: { data: { error: 'Not allowed' } } }); const { result } = setup(); await waitFor(() => expect(result.current.loading).toBe(false)); - expect(addToast).toHaveBeenCalledWith('Not allowed', 'error', undefined); + expect(toastError).toHaveBeenCalledWith('Not allowed'); }); it('FE-COMP-PLACEDUPES-009: keeping side a merges a into b, drops the pair and reports the change', async () => { @@ -162,7 +161,7 @@ describe('usePlaceDuplicates', () => { expect(result.current.lastMerge).toBeNull(); expect(result.current.busy).toBeNull(); expect(onChanged).not.toHaveBeenCalled(); - expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined); + expect(toastError).toHaveBeenCalledWith('common.error'); }); it('FE-COMP-PLACEDUPES-012: marks the pair busy while it merges and ignores a second click', async () => { @@ -210,7 +209,7 @@ describe('usePlaceDuplicates', () => { }); expect(result.current.pairs).toEqual([PAIR, OTHER_PAIR]); expect(onChanged).not.toHaveBeenCalled(); - expect(addToast).toHaveBeenCalledWith('Gone', 'error', undefined); + expect(toastError).toHaveBeenCalledWith('Gone'); }); it('FE-COMP-PLACEDUPES-015: undo takes the last merge back, clears it and reloads the pairs', async () => { @@ -256,7 +255,7 @@ describe('usePlaceDuplicates', () => { expect(result.current.busy).toBeNull(); expect(onChanged).toHaveBeenCalledTimes(1); expect(duplicates).toHaveBeenCalledTimes(1); - expect(addToast).toHaveBeenCalledWith('common.error', 'error', undefined); + expect(toastError).toHaveBeenCalledWith('common.error'); }); it('FE-COMP-PLACEDUPES-018: reload asks the server for the pairs again', async () => { diff --git a/client/src/components/Map/placeNameLabels.ts b/client/src/components/Map/placeNameLabels.ts index 41fb56297..c7c3c96ab 100644 --- a/client/src/components/Map/placeNameLabels.ts +++ b/client/src/components/Map/placeNameLabels.ts @@ -11,7 +11,7 @@ import './placeNames.css'; * A place folded into a cluster has no element, so it has no label either. */ -export const PLACE_NAME_ATTR = 'data-place-name'; +const PLACE_NAME_ATTR = 'data-place-name'; const PRIORITY_ATTR = 'data-place-name-priority'; const LABEL_CLASS = 'trek-place-name'; const HIDDEN_ATTR = 'data-hidden'; diff --git a/client/src/components/Map/ratingBadge.css b/client/src/components/Map/ratingBadge.css new file mode 100644 index 000000000..c51d08cb5 --- /dev/null +++ b/client/src/components/Map/ratingBadge.css @@ -0,0 +1,6 @@ +/* The rating on a map marker's corner: amber with a white figure, like the list's badge. */ +.trek-rating-badge { + background: #f59e0b; + color: #fff; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45); +} diff --git a/client/src/components/Map/ratingBadge.test.ts b/client/src/components/Map/ratingBadge.test.ts index 19d91c2dc..c917240ab 100644 --- a/client/src/components/Map/ratingBadge.test.ts +++ b/client/src/components/Map/ratingBadge.test.ts @@ -27,11 +27,11 @@ describe('cornerBadgeHtml', () => { const html = cornerBadgeHtml([2, 5], 4.5, true, -4); expect(html).toContain('2 · 5'); expect(html).toContain('bottom:-4px;inset-inline-end:-4px'); - expect(html).not.toContain('#fbbf24'); + expect(html).not.toContain('trek-rating-badge'); }); it('FE-MAP-RATINGBADGE-102: without numbers the rating shows when asked for, else nothing', () => { - expect(cornerBadgeHtml(null, 4, true, -2)).toContain('#fbbf24'); + expect(cornerBadgeHtml(null, 4, true, -2)).toContain('trek-rating-badge'); expect(cornerBadgeHtml([], 4, false, -2)).toBe(''); expect(cornerBadgeHtml([3], null, true, -2)).toContain('height:18px'); }); diff --git a/client/src/components/Map/ratingBadge.ts b/client/src/components/Map/ratingBadge.ts index fd1b5ec32..c43396c99 100644 --- a/client/src/components/Map/ratingBadge.ts +++ b/client/src/components/Map/ratingBadge.ts @@ -1,3 +1,5 @@ +import './ratingBadge.css'; + /** * The rating a place carries, as a disc on the corner of its marker. * @@ -12,15 +14,15 @@ export function ratingBadgeHtml(rating: number | null | undefined): string { if (typeof rating !== 'number' || !(rating > 0)) return ''; const label = Number.isInteger(rating) ? String(rating) : rating.toFixed(1); - return `${label}`; diff --git a/client/src/index.css b/client/src/index.css index e2b5feafc..b7be17add 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -1171,9 +1171,6 @@ body { /* ── Leaflet z-index ───────────────────────────── */ .leaflet-container { z-index: 0; - /* Leaflet's own grey showed as a bright band past the edge of the world when a map - framed places on several continents, and while tiles were still loading. */ - background: var(--bg-secondary); } .leaflet-pane { z-index: 0 !important; diff --git a/client/src/main.tsx b/client/src/main.tsx index 7eb1934ea..2031ff903 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -25,6 +25,7 @@ import '@fontsource/geist-sans/600.css' // several .leaflet-* styles. import 'leaflet/dist/leaflet.css' import './index.css' +import './styles/leafletCanvas.css' import './native/nativeApp.css' import './styles/rtl.css' import './styles/pageTransition.css' diff --git a/client/src/repo/mapMatchRepo.ts b/client/src/repo/mapMatchRepo.ts index de340ea47..a0377ac5d 100644 --- a/client/src/repo/mapMatchRepo.ts +++ b/client/src/repo/mapMatchRepo.ts @@ -61,5 +61,6 @@ export async function searchMapSpots(query: string, lang?: string): Promise toMatch(row, q)).filter((m): m is MapMatch => m !== null); + const rows: readonly unknown[] = res?.places ?? []; + return rows.map((row: unknown) => toMatch(row, q)).filter((m: MapMatch | null): m is MapMatch => m !== null); } diff --git a/client/src/styles/leafletCanvas.css b/client/src/styles/leafletCanvas.css new file mode 100644 index 000000000..cffb6995b --- /dev/null +++ b/client/src/styles/leafletCanvas.css @@ -0,0 +1,5 @@ +/* Leaflet's own grey showed as a bright band past the edge of the world when a map + framed places on several continents, and while tiles were still loading. */ +.leaflet-container { + background: var(--bg-secondary); +} diff --git a/client/tests/unit/mobile/MNavRail.test.tsx b/client/tests/unit/mobile/MNavRail.test.tsx index eb8bc6001..803ab540d 100644 --- a/client/tests/unit/mobile/MNavRail.test.tsx +++ b/client/tests/unit/mobile/MNavRail.test.tsx @@ -39,7 +39,7 @@ describe('MNavRail', () => { seedAddons(['vacay', 'journey', 'atlas', 'collections']); render(, { initialEntries: ['/dashboard'] }); - for (const name of ['My Trips', 'Vacay', 'Journey', 'Atlas', 'Collections', 'Settings']) { + for (const name of ['My Trips', 'Vacay', 'Journey', 'Atlas', 'Places', 'Settings']) { expect(within(rail()).getByRole('button', { name })).toBeInTheDocument(); } expect(within(rail()).queryByRole('button', { name: 'More' })).not.toBeInTheDocument(); diff --git a/client/tests/unit/mobile/collections/MCollEditSheet.test.tsx b/client/tests/unit/mobile/collections/MCollEditSheet.test.tsx index 4df8e7e96..b207c9411 100644 --- a/client/tests/unit/mobile/collections/MCollEditSheet.test.tsx +++ b/client/tests/unit/mobile/collections/MCollEditSheet.test.tsx @@ -153,6 +153,7 @@ describe('MCollEditSheet', () => { name: 'Hamburg', color: '#38BDF8', description: null, + icon: 'Bookmark', links: [{ label: 'Guide', url: 'https://hamburg.de' }], }) // An edit must not re-navigate the way a create does. diff --git a/client/tests/unit/mobile/settings/MMobileNavCustomizer.test.tsx b/client/tests/unit/mobile/settings/MMobileNavCustomizer.test.tsx index 773fea4e7..6038f939c 100644 --- a/client/tests/unit/mobile/settings/MMobileNavCustomizer.test.tsx +++ b/client/tests/unit/mobile/settings/MMobileNavCustomizer.test.tsx @@ -37,7 +37,7 @@ describe('MMobileNavCustomizer', () => { render(); expect(rowLabels('In the bar')).toEqual(['Vacay', 'Journey']); - expect(rowLabels('Under “More”')).toEqual(['Atlas', 'Collections']); + expect(rowLabels('Under “More”')).toEqual(['Atlas', 'Places']); }); it('FE-MOB-SETNAVC-002: Dashboard is listed pinned and has no reorder buttons', () => { diff --git a/server/src/nest/places-library/place-identities.service.ts b/server/src/nest/places-library/place-identities.service.ts index 3709187db..63f0038e0 100644 --- a/server/src/nest/places-library/place-identities.service.ts +++ b/server/src/nest/places-library/place-identities.service.ts @@ -1,4 +1,4 @@ -import { UserPlaceLinks } from '../../db/entities/UserPlaceLinks.entity'; +import { UserPlaceLinks, UserPlaceLinksLinkedBy } from '../../db/entities/UserPlaceLinks.entity'; import { UserPlaceMergeDismissals } from '../../db/entities/UserPlaceMergeDismissals.entity'; import { UserPlaceMerges } from '../../db/entities/UserPlaceMerges.entity'; import { UserPlaces } from '../../db/entities/UserPlaces.entity'; @@ -93,11 +93,11 @@ export class PlaceIdentitiesService { } const first = uses[0]; if (!first) throw placeNotFound(); - const target = - request.identity_id === undefined ? { facts: await this.factsOfUse(reach, first) } : { id: request.identity_id }; + const joining = request.identity_id; const identityId = await this.uow.transactional(async () => { - const id = 'id' in target ? target.id : await this.identities.createOwn(user.id, target.facts); - await this.attach(user.id, id, uses, 'user'); + const id = + joining !== undefined ? joining : await this.identities.createOwn(user.id, await this.factsOfUse(reach, first)); + await this.attach(user.id, id, uses, UserPlaceLinksLinkedBy.USER); await this.identities.touch(user.id, id); await this.prune(user.id); return id; @@ -288,7 +288,7 @@ export class PlaceIdentitiesService { google_ftid: first.google_ftid, osm_id: first.osm_id, }); - await this.attach(userId, id, usesOfRows(rows), 'merge'); + await this.attach(userId, id, usesOfRows(rows), UserPlaceLinksLinkedBy.MERGE); return id; } diff --git a/shared/src/places-library/place-identity.schema.ts b/shared/src/places-library/place-identity.schema.ts index df3ba188d..ea4b4a761 100644 --- a/shared/src/places-library/place-identity.schema.ts +++ b/shared/src/places-library/place-identity.schema.ts @@ -47,7 +47,9 @@ export const placesLibraryLinkRequestSchema = z export type PlacesLibraryLinkRequest = z.infer; /** Take one use out of the user's own place again. */ -export const placesLibraryUnlinkRequestSchema = placesLibraryUseSchema; +export const placesLibraryUnlinkRequestSchema = placesLibraryUseSchema.describe( + 'The trip place or saved place to take out of the own place it belongs to', +); export type PlacesLibraryUnlinkRequest = PlacesLibraryUse; /** The entry a use belongs to after the change, null when it is out of reach by now. */