implemented usePrompt hook

main
Inga 🏳‍🌈 6 months ago
parent e6bf07cbd0
commit 47b2aeb48b
  1. 14
      src/routePlanner/hooks/usePrompt/index.ts
  2. 13
      src/routePlanner/marker.tsx

@ -0,0 +1,14 @@
import { useCallback } from 'preact/hooks';
export const usePrompt = (
message: string,
defaultValue: string,
onChange: (newValue: string) => void,
) => {
return useCallback(() => {
const newValue = prompt(message, defaultValue);
if (newValue?.length) {
onChange(newValue);
}
}, [message, defaultValue, onChange]);
};

@ -1,13 +1,12 @@
import { useCallback } from 'preact/hooks';
import { usePrompt } from './hooks/usePrompt';
import type { MarkerProps } from './types';
export const MarkerComponent = ({ marker, isFirst, isLast }: MarkerProps) => {
const changeLongLabel = useCallback(() => {
const newLongLabel = prompt('Enter new label', marker.longLabel);
if (newLongLabel?.length) {
marker.changeLongLabel(newLongLabel);
}
}, [marker]);
const changeLongLabel = usePrompt(
'Enter new label',
marker.longLabel,
marker.changeLongLabel,
);
return (
<li key={marker.key}>

Loading…
Cancel
Save