mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
ae79ab8dad
The compare switch in a tour's detail showed whenever the detail sat beside the plan map, but the map draws no comparison in road trip mode or with the trip overview open. Pressing it there turned the switch on while nothing appeared on the map. The plan map now tells the compare store whether it can draw a comparison. The detail offers the switch only then, and turning to the road trip or the overview, or leaving the map, ends a running comparison.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
/**
|
|
* ACT-02: the actual track one tour is compared with on the plan map. Only
|
|
* ids: the planned line and the recorded one are both places of the trip, so
|
|
* the map reads them where they are kept and a changed recording or plan
|
|
* shows changed. Comparing is looking; it writes nothing.
|
|
*/
|
|
interface ActivityComparison {
|
|
/** The planned tour, whose detail is open. */
|
|
tourPlaceId: number;
|
|
/** The recording linked to it as its actual track. */
|
|
trackPlaceId: number;
|
|
}
|
|
|
|
interface TourActivityCompareState {
|
|
comparison: ActivityComparison | null;
|
|
/**
|
|
* Whether the plan map can draw a comparison right now. The map says so
|
|
* itself: in road trip mode, with the trip overview open or on the phone it
|
|
* draws other lines, and the detail then offers no switch that would do
|
|
* nothing.
|
|
*/
|
|
mapAvailable: boolean;
|
|
show: (comparison: ActivityComparison | null) => void;
|
|
clear: () => void;
|
|
/** Set by the plan map; a map that can no longer compare ends the comparison too. */
|
|
setMapAvailable: (available: boolean) => void;
|
|
}
|
|
|
|
export const useTourActivityCompareStore = create<TourActivityCompareState>((set) => ({
|
|
comparison: null,
|
|
mapAvailable: false,
|
|
show: (comparison) => set({ comparison }),
|
|
clear: () => set({ comparison: null }),
|
|
setMapAvailable: (available) => set(available ? { mapAvailable: true } : { mapAvailable: false, comparison: null }),
|
|
}));
|