reorganized project layout (useMarkers)

main
Inga 🏳‍🌈 1 year ago
parent 28401a26b2
commit e48de70750
  1. 12
      src/routePlanner/hooks/useMarkers/index.ts
  2. 4
      src/routePlanner/hooks/useMarkers/reducer.test.ts
  3. 18
      src/routePlanner/hooks/useMarkers/reducer.ts
  4. 2
      src/routePlanner/index.tsx

@ -0,0 +1,12 @@
import { useMemo, useReducer } from 'preact/hooks';
import { createChangeStateMethods, markersReducer } from './reducer';
export const useMarkers = () => {
const [markers, dispatchMarkers] = useReducer(markersReducer, []);
const changeStateMethods = useMemo(
() => createChangeStateMethods(dispatchMarkers),
[],
);
return [markers, changeStateMethods] as const;
};

@ -1,10 +1,10 @@
import t from 'tap';
import { Marker } from './types';
import { Marker } from '../../types';
import {
ReducerAction,
createChangeStateMethods,
markersReducer,
} from './useMarkers.js';
} from './reducer.js';
// Testing entire `useMarkers` custom hook would require us to create test preact components here
// and render them into virtual DOM and check the results, which is just too much hassle

@ -1,8 +1,8 @@
import { nanoid } from 'nanoid';
import { Dispatch, useMemo, useReducer } from 'preact/hooks';
import { reorderElements } from '../shared/collections.js';
import { Coordinates } from '../shared/types';
import { Marker, ReorderMarkersParams } from './types';
import type { Dispatch } from 'preact/hooks';
import { reorderElements } from '../../../shared/collections.js';
import { Coordinates } from '../../../shared/types';
import { Marker, ReorderMarkersParams } from '../../types';
type GenericReducerAction<TType extends string, TData> = {
type: TType;
@ -158,13 +158,3 @@ export const createChangeStateMethods = (
data: { oldIndex, newIndex },
}),
});
export const useMarkers = () => {
const [markers, dispatchMarkers] = useReducer(markersReducer, []);
const changeStateMethods = useMemo(
() => createChangeStateMethods(dispatchMarkers),
[],
);
return [markers, changeStateMethods] as const;
};

@ -1,7 +1,7 @@
import { ExportComponent } from './export';
import { MapComponent } from './map';
import { MarkersComponent } from './markers';
import { useMarkers } from './useMarkers';
import { useMarkers } from './hooks/useMarkers';
import './style.css';

Loading…
Cancel
Save