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.
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
import { useCallback, useEffect } from 'react';
|
|
|
|
import { useSettingsStore } from '../../store/settingsStore';
|
|
import { controlBoxes, layoutPlaceNames, PLACE_NAMES_CONTROLS } from './placeNameLabels';
|
|
|
|
/** Whether the trip map shows its place names, the reader's own setting (#2796). */
|
|
export function usePlaceNamesSetting(): boolean {
|
|
return useSettingsStore((s) => s.settings.map_place_labels) === true;
|
|
}
|
|
|
|
/**
|
|
* Keeps the place names of one map laid out: once after every change of the markers
|
|
* (a cluster opening, a day picked) and after every move or zoom the renderer reports
|
|
* through `listen`. Both renderers share it; only how they report a move differs.
|
|
*/
|
|
export function usePlaceNameLayout(
|
|
enabled: boolean,
|
|
/** The element the markers live in, or null while the map is not up yet. Keep it stable (useCallback). */
|
|
getContainer: () => HTMLElement | null,
|
|
/** Subscribes `run` to the renderer's move and zoom ends and returns the unsubscribe. Keep it stable too. */
|
|
listen: (run: () => void) => () => void
|
|
): void {
|
|
useEffect(() => {
|
|
const container = getContainer();
|
|
if (!container) return;
|
|
let frame = 0;
|
|
const run = () => {
|
|
cancelAnimationFrame(frame);
|
|
frame = requestAnimationFrame(() => {
|
|
const scope = container.parentElement ?? container;
|
|
const controls = enabled ? controlBoxes(scope, PLACE_NAMES_CONTROLS).filter((b) => b.x1 > b.x0) : [];
|
|
layoutPlaceNames(container, enabled, controls);
|
|
});
|
|
};
|
|
run();
|
|
if (!enabled) return () => cancelAnimationFrame(frame);
|
|
const stop = listen(run);
|
|
// A marker added or taken away (a cluster splitting, a selection rebuilding the pins).
|
|
const observer = new MutationObserver(run);
|
|
observer.observe(container, { childList: true, subtree: true });
|
|
return () => {
|
|
cancelAnimationFrame(frame);
|
|
stop();
|
|
observer.disconnect();
|
|
};
|
|
}, [enabled, getContainer, listen]);
|
|
}
|
|
|
|
/** The part of either GL map the names need. */
|
|
interface NamesGlMap {
|
|
getContainer: () => HTMLElement;
|
|
on: (type: 'moveend', listener: () => void) => unknown;
|
|
off: (type: 'moveend', listener: () => void) => unknown;
|
|
}
|
|
|
|
/** The GL map's wiring: its container, and a layout after every move or zoom ends. */
|
|
export function useGlPlaceNames(map: NamesGlMap | null): void {
|
|
const enabled = usePlaceNamesSetting();
|
|
const getContainer = useCallback(() => map?.getContainer() ?? null, [map]);
|
|
const listen = useCallback(
|
|
(run: () => void) => {
|
|
if (!map) return () => {};
|
|
map.on('moveend', run);
|
|
return () => {
|
|
map.off('moveend', run);
|
|
};
|
|
},
|
|
[map]
|
|
);
|
|
usePlaceNameLayout(enabled, getContainer, listen);
|
|
}
|