mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(collections): own order, KML/KMZ import, copy options, position search, place names on the trip map
- A list keeps its own order: drag a place by its grip (desktop and phone) or move it with the arrow keys. Reordering is off while a search or filter hides places and the list says why. New PUT /collections/:id/places/reorder and the MCP tool reorder_collection_places; new places go to the end. Client and server now order ties the same way (sort_order, oldest first, id). - Copying saved places into a trip no longer takes their notes and tags along unasked. The picker offers both; a tag taken along becomes a trip tag (a trip tag of the same name is reused), never someone's personal tag. - The source trip and place a saved place names are only kept when the user can open that trip and the place belongs to it. - A KML or KMZ map can be read into a list: the dialog lists every placemark to keep or leave out and says which entries were skipped and why (POST /collections/map/read writes nothing; the import does). - A saved place without coordinates says so and can be looked up on the map from its edit form, on the phone too, where a missing position could not be added at all. A typed address without a pick says it will not be on the map. - The trip map can show the place names beside the pins (desktop and phone, both renderers). Names that would cover another pin or a control give way, the selected place and the planned stops first.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// FE-COMP-LOCSEARCH-001 to FE-COMP-LOCSEARCH-004: the position search behind the
|
||||
// "find the position" rows of the saved place editors (#2837).
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { searchMapSpots } from '../../repo/mapMatchRepo';
|
||||
import { useLocationSearch } from './useLocationSearch';
|
||||
|
||||
vi.mock('../../repo/mapMatchRepo', () => ({ searchMapSpots: vi.fn() }));
|
||||
vi.mock('../../hooks/usePlaceLanguage', () => ({ usePlaceLanguage: () => 'de' }));
|
||||
|
||||
const SPOT = { lat: 35.66, lng: 139.7, label: 'Kissa Sakaiki, Shibuya', address: 'Shibuya' };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(searchMapSpots).mockReset();
|
||||
});
|
||||
|
||||
describe('useLocationSearch', () => {
|
||||
it('FE-COMP-LOCSEARCH-001: searches in the place language and lists the hits', async () => {
|
||||
vi.mocked(searchMapSpots).mockResolvedValue([SPOT]);
|
||||
const { result } = renderHook(() => useLocationSearch(vi.fn()));
|
||||
act(() => result.current.setQuery('kissa'));
|
||||
await act(() => result.current.search());
|
||||
expect(searchMapSpots).toHaveBeenCalledWith('kissa', 'de');
|
||||
expect(result.current.results).toEqual([SPOT]);
|
||||
expect(result.current.noResults).toBe(false);
|
||||
expect(result.current.searching).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-COMP-LOCSEARCH-002: a blank query asks nothing', async () => {
|
||||
const { result } = renderHook(() => useLocationSearch(vi.fn()));
|
||||
act(() => result.current.setQuery(' '));
|
||||
await act(() => result.current.search());
|
||||
expect(searchMapSpots).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('FE-COMP-LOCSEARCH-003: no hits and a failed search both say there was nothing', async () => {
|
||||
vi.mocked(searchMapSpots).mockResolvedValueOnce([]).mockRejectedValueOnce(new Error('down'));
|
||||
const { result } = renderHook(() => useLocationSearch(vi.fn()));
|
||||
act(() => result.current.setQuery('nowhere'));
|
||||
await act(() => result.current.search());
|
||||
expect(result.current.noResults).toBe(true);
|
||||
await act(() => result.current.search());
|
||||
expect(result.current.noResults).toBe(true);
|
||||
expect(result.current.results).toEqual([]);
|
||||
});
|
||||
|
||||
it('FE-COMP-LOCSEARCH-004: a pick hands the spot over and clears the search', async () => {
|
||||
vi.mocked(searchMapSpots).mockResolvedValue([SPOT]);
|
||||
const onPick = vi.fn();
|
||||
const { result } = renderHook(() => useLocationSearch(onPick));
|
||||
act(() => result.current.setQuery('kissa'));
|
||||
await act(() => result.current.search());
|
||||
act(() => result.current.pick(SPOT));
|
||||
expect(onPick).toHaveBeenCalledWith(SPOT);
|
||||
expect(result.current.query).toBe('');
|
||||
expect(result.current.results).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import { usePlaceLanguage } from '../../hooks/usePlaceLanguage';
|
||||
import { type MapMatch, searchMapSpots } from '../../repo/mapMatchRepo';
|
||||
|
||||
/**
|
||||
* A small map search that only looks for a position (#2837). It backs the
|
||||
* "find the position" row in the place editors that have no search of their own:
|
||||
* nothing is written until the reader picks a hit, and the pick hands back only
|
||||
* coordinates and an address, so a typed name or a custom note stays as it was.
|
||||
* Desktop and phone render their own markup over it.
|
||||
*/
|
||||
export function useLocationSearch(onPick: (spot: MapMatch) => void) {
|
||||
const placeLang = usePlaceLanguage();
|
||||
const [query, setQuery] = useState('');
|
||||
const [results, setResults] = useState<MapMatch[]>([]);
|
||||
const [searching, setSearching] = useState(false);
|
||||
// An empty answer has to say so; a list that just stays closed reads as a broken button.
|
||||
const [noResults, setNoResults] = useState(false);
|
||||
|
||||
const search = async () => {
|
||||
if (!query.trim() || searching) return;
|
||||
setSearching(true);
|
||||
setNoResults(false);
|
||||
try {
|
||||
const spots = await searchMapSpots(query, placeLang);
|
||||
setResults(spots);
|
||||
setNoResults(spots.length === 0);
|
||||
} catch {
|
||||
setResults([]);
|
||||
setNoResults(true);
|
||||
} finally {
|
||||
setSearching(false);
|
||||
}
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
setQuery('');
|
||||
setResults([]);
|
||||
setNoResults(false);
|
||||
};
|
||||
|
||||
const pick = (spot: MapMatch) => {
|
||||
onPick(spot);
|
||||
reset();
|
||||
};
|
||||
|
||||
return { query, setQuery, results, searching, noResults, search, pick, reset };
|
||||
}
|
||||
Reference in New Issue
Block a user