mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
style(client): prettier on the files this branch touched
This commit is contained in:
@@ -22,7 +22,9 @@ describe('usePlanMapViewport', () => {
|
||||
});
|
||||
|
||||
it('raeumt ihn auch weg, sobald die Karte nicht mehr zu sehen ist, und nimmt dann nichts an', () => {
|
||||
const { result, rerender } = renderHook(({ shown }) => usePlanMapViewport(5, shown), { initialProps: { shown: true } });
|
||||
const { result, rerender } = renderHook(({ shown }) => usePlanMapViewport(5, shown), {
|
||||
initialProps: { shown: true },
|
||||
});
|
||||
act(() => result.current(KYOTO));
|
||||
rerender({ shown: false });
|
||||
expect(useTripStore.getState().planMapViewport).toBeNull();
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { useCallback, useEffect } from 'react'
|
||||
import { useTripStore } from '../store/tripStore'
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useTripStore } from '../store/tripStore';
|
||||
|
||||
interface Bounds { south: number; west: number; north: number; east: number }
|
||||
interface Bounds {
|
||||
south: number;
|
||||
west: number;
|
||||
north: number;
|
||||
east: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hands the plan map's viewport to the trip store, where the place search reads
|
||||
@@ -11,16 +16,19 @@ interface Bounds { south: number; west: number; north: number; east: number }
|
||||
* to lean on, and falls back to the day and the trip.
|
||||
*/
|
||||
export function usePlanMapViewport(tripId: number, shown = true): (bounds: Bounds) => void {
|
||||
const setPlanMapViewport = useTripStore((s) => s.setPlanMapViewport)
|
||||
const setPlanMapViewport = useTripStore((s) => s.setPlanMapViewport);
|
||||
|
||||
useEffect(() => {
|
||||
if (!shown) setPlanMapViewport(null)
|
||||
return () => setPlanMapViewport(null)
|
||||
}, [shown, tripId, setPlanMapViewport])
|
||||
if (!shown) setPlanMapViewport(null);
|
||||
return () => setPlanMapViewport(null);
|
||||
}, [shown, tripId, setPlanMapViewport]);
|
||||
|
||||
return useCallback((bounds: Bounds) => {
|
||||
if (!shown || !Number.isFinite(tripId)) return
|
||||
const { south, west, north, east } = bounds
|
||||
setPlanMapViewport({ tripId, south, west, north, east })
|
||||
}, [shown, tripId, setPlanMapViewport])
|
||||
return useCallback(
|
||||
(bounds: Bounds) => {
|
||||
if (!shown || !Number.isFinite(tripId)) return;
|
||||
const { south, west, north, east } = bounds;
|
||||
setPlanMapViewport({ tripId, south, west, north, east });
|
||||
},
|
||||
[shown, tripId, setPlanMapViewport]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user