implemented usePrompt hook

main
Inga 🏳‍🌈 1 year 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'; import type { MarkerProps } from './types';
export const MarkerComponent = ({ marker, isFirst, isLast }: MarkerProps) => { export const MarkerComponent = ({ marker, isFirst, isLast }: MarkerProps) => {
const changeLongLabel = useCallback(() => { const changeLongLabel = usePrompt(
const newLongLabel = prompt('Enter new label', marker.longLabel); 'Enter new label',
if (newLongLabel?.length) { marker.longLabel,
marker.changeLongLabel(newLongLabel); marker.changeLongLabel,
} );
}, [marker]);
return ( return (
<li key={marker.key}> <li key={marker.key}>

Loading…
Cancel
Save