From e6bf07cbd01459e05cc2135ae4d219ce93e5fa63 Mon Sep 17 00:00:00 2001 From: Inga Date: Sun, 19 Nov 2023 03:46:12 +0000 Subject: [PATCH] code cleanup --- src/routePlanner/export.tsx | 4 +--- src/routePlanner/hooks/useMap/index.ts | 2 +- src/routePlanner/hooks/useMapClick/index.ts | 9 +++------ src/routePlanner/hooks/useMarkers/reducer.test.ts | 2 +- src/routePlanner/hooks/useMarkers/reducer.ts | 4 ++-- .../hooks/useMarkersOnMap/getLayersForMarkers.ts | 2 +- src/routePlanner/hooks/useMarkersOnMap/index.ts | 7 +++---- src/routePlanner/hooks/useSortable/index.ts | 7 +++---- src/routePlanner/index.tsx | 2 +- src/routePlanner/map.tsx | 3 +-- src/routePlanner/marker.tsx | 2 +- src/routePlanner/markers.tsx | 4 ++-- src/routePlanner/types.ts | 2 +- 13 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/routePlanner/export.tsx b/src/routePlanner/export.tsx index 0e9de65..21c8621 100644 --- a/src/routePlanner/export.tsx +++ b/src/routePlanner/export.tsx @@ -1,7 +1,5 @@ import { exportMarkersToGpx } from '../exporters/gpx'; -import { ExportProps } from './types'; - -import 'leaflet/dist/leaflet.css'; +import type { ExportProps } from './types'; export const ExportComponent = ({ markers }: ExportProps) => { return ( diff --git a/src/routePlanner/hooks/useMap/index.ts b/src/routePlanner/hooks/useMap/index.ts index 83992f5..cadcb52 100644 --- a/src/routePlanner/hooks/useMap/index.ts +++ b/src/routePlanner/hooks/useMap/index.ts @@ -1,5 +1,5 @@ import leaflet, { type Map } from 'leaflet'; -import { Ref, useEffect, useRef } from 'preact/hooks'; +import { type Ref, useEffect, useRef } from 'preact/hooks'; import 'leaflet/dist/leaflet.css'; diff --git a/src/routePlanner/hooks/useMapClick/index.ts b/src/routePlanner/hooks/useMapClick/index.ts index a5d6609..f7f8a71 100644 --- a/src/routePlanner/hooks/useMapClick/index.ts +++ b/src/routePlanner/hooks/useMapClick/index.ts @@ -1,13 +1,11 @@ import leaflet from 'leaflet'; -import { Ref, useEffect } from 'preact/hooks'; - -import 'leaflet/dist/leaflet.css'; -import { Coordinates } from '../../../shared/types'; +import { type Ref, useEffect } from 'preact/hooks'; +import type { Coordinates } from '../../../shared/types'; export const useMapClick = ( mapRef: Readonly>, onMapClick: (leaflet: Coordinates) => void, -) => { +) => useEffect(() => { const map = mapRef.current; if (!map) { @@ -23,4 +21,3 @@ export const useMapClick = ( map.removeEventListener('click', handler); }; }, [mapRef, onMapClick]); -}; diff --git a/src/routePlanner/hooks/useMarkers/reducer.test.ts b/src/routePlanner/hooks/useMarkers/reducer.test.ts index 0a6b978..4294f75 100644 --- a/src/routePlanner/hooks/useMarkers/reducer.test.ts +++ b/src/routePlanner/hooks/useMarkers/reducer.test.ts @@ -1,5 +1,5 @@ import t from 'tap'; -import { Marker } from '../../types'; +import type { Marker } from '../../types'; import { ReducerAction, createChangeStateMethods, diff --git a/src/routePlanner/hooks/useMarkers/reducer.ts b/src/routePlanner/hooks/useMarkers/reducer.ts index 69f6afb..dd19ae6 100644 --- a/src/routePlanner/hooks/useMarkers/reducer.ts +++ b/src/routePlanner/hooks/useMarkers/reducer.ts @@ -1,8 +1,8 @@ import { nanoid } from 'nanoid'; import type { Dispatch } from 'preact/hooks'; import { reorderElements } from '../../../shared/collections.js'; -import { Coordinates } from '../../../shared/types'; -import { Marker, ReorderListParams } from '../../types'; +import type { Coordinates } from '../../../shared/types'; +import type { Marker, ReorderListParams } from '../../types'; type GenericReducerAction = { type: TType; diff --git a/src/routePlanner/hooks/useMarkersOnMap/getLayersForMarkers.ts b/src/routePlanner/hooks/useMarkersOnMap/getLayersForMarkers.ts index 7c2b90e..b163df2 100644 --- a/src/routePlanner/hooks/useMarkersOnMap/getLayersForMarkers.ts +++ b/src/routePlanner/hooks/useMarkersOnMap/getLayersForMarkers.ts @@ -1,5 +1,5 @@ import leaflet from 'leaflet'; -import { Marker } from '../../types'; +import type { Marker } from '../../types'; export const getLayersForMarkers = (markers: Marker[]) => [ // lines diff --git a/src/routePlanner/hooks/useMarkersOnMap/index.ts b/src/routePlanner/hooks/useMarkersOnMap/index.ts index 5a63deb..38a558f 100644 --- a/src/routePlanner/hooks/useMarkersOnMap/index.ts +++ b/src/routePlanner/hooks/useMarkersOnMap/index.ts @@ -1,12 +1,12 @@ import leaflet from 'leaflet'; -import { Ref, useEffect } from 'preact/hooks'; +import { type Ref, useEffect } from 'preact/hooks'; +import type { Marker } from '../../types'; import { getLayersForMarkers } from './getLayersForMarkers'; -import { Marker } from '../../types'; export const useMarkersOnMap = ( mapRef: Readonly>, markers: Marker[], -) => { +) => useEffect(() => { const map = mapRef.current; if (!map) { @@ -26,4 +26,3 @@ export const useMarkersOnMap = ( } }; }, [mapRef, markers]); -}; diff --git a/src/routePlanner/hooks/useSortable/index.ts b/src/routePlanner/hooks/useSortable/index.ts index af657cf..ff062b8 100644 --- a/src/routePlanner/hooks/useSortable/index.ts +++ b/src/routePlanner/hooks/useSortable/index.ts @@ -1,11 +1,11 @@ -import { useEffect, Ref } from 'preact/hooks'; +import { type Ref, useEffect } from 'preact/hooks'; import Sortable from 'sortablejs'; -import { ReorderListParams } from '../../types'; +import type { ReorderListParams } from '../../types'; export const useSortable = ( listContainerRef: Readonly>, onListReorder: (params: ReorderListParams) => void, -) => { +) => useEffect(() => { if (!listContainerRef.current) { return; @@ -30,4 +30,3 @@ export const useSortable = ( sortable.destroy(); }; }, [listContainerRef, onListReorder]); -}; diff --git a/src/routePlanner/index.tsx b/src/routePlanner/index.tsx index 880ef2a..0d71e04 100644 --- a/src/routePlanner/index.tsx +++ b/src/routePlanner/index.tsx @@ -1,7 +1,7 @@ import { ExportComponent } from './export'; +import { useMarkers } from './hooks/useMarkers'; import { MapComponent } from './map'; import { MarkersComponent } from './markers'; -import { useMarkers } from './hooks/useMarkers'; import './style.css'; diff --git a/src/routePlanner/map.tsx b/src/routePlanner/map.tsx index 4b82b9f..a9a2cda 100644 --- a/src/routePlanner/map.tsx +++ b/src/routePlanner/map.tsx @@ -1,9 +1,8 @@ import { useRef } from 'preact/hooks'; -import { MapProps } from './types'; - import { useMap } from './hooks/useMap'; import { useMapClick } from './hooks/useMapClick'; import { useMarkersOnMap } from './hooks/useMarkersOnMap'; +import type { MapProps } from './types'; const defaultMapViewParameters = [ [47.42111, 10.98528], diff --git a/src/routePlanner/marker.tsx b/src/routePlanner/marker.tsx index 72513d3..3b5dfc1 100644 --- a/src/routePlanner/marker.tsx +++ b/src/routePlanner/marker.tsx @@ -1,5 +1,5 @@ import { useCallback } from 'preact/hooks'; -import { MarkerProps } from './types'; +import type { MarkerProps } from './types'; export const MarkerComponent = ({ marker, isFirst, isLast }: MarkerProps) => { const changeLongLabel = useCallback(() => { diff --git a/src/routePlanner/markers.tsx b/src/routePlanner/markers.tsx index d57da03..1140667 100644 --- a/src/routePlanner/markers.tsx +++ b/src/routePlanner/markers.tsx @@ -1,7 +1,7 @@ import { useRef } from 'preact/hooks'; -import { MarkerComponent } from './marker'; -import { MarkersProps } from './types'; import { useSortable } from './hooks/useSortable'; +import { MarkerComponent } from './marker'; +import type { MarkersProps } from './types'; export const MarkersComponent = ({ markers, diff --git a/src/routePlanner/types.ts b/src/routePlanner/types.ts index 0208e85..4643975 100644 --- a/src/routePlanner/types.ts +++ b/src/routePlanner/types.ts @@ -1,4 +1,4 @@ -import { Coordinates, Waypoint } from '../shared/types'; +import type { Coordinates, Waypoint } from '../shared/types'; export type Marker = Waypoint & { key: string;