isFirst / isLast

main
Inga 🏳‍🌈 1 year ago
parent 748334108c
commit 1d79801e59
  1. 6
      src/routePlanner/marker.tsx
  2. 9
      src/routePlanner/markers.tsx
  3. 6
      src/routePlanner/types.ts

@ -1,14 +1,14 @@
import { MarkerProps } from './types'; import { MarkerProps } from './types';
export const MarkerComponent = ({ marker }: MarkerProps) => { export const MarkerComponent = ({ marker, isFirst, isLast }: MarkerProps) => {
return ( return (
<li key={marker.key}> <li key={marker.key}>
{`Waypoint ${marker.label} (${marker.key.substring(0, 4)})`} {`Waypoint ${marker.label} (${marker.key.substring(0, 4)})`}
<span class="buttons"> <span class="buttons">
<button onClick={marker.moveUp} disabled={!marker.moveUp}> <button onClick={marker.moveUp} disabled={isFirst}>
🔼 🔼
</button> </button>
<button onClick={marker.moveDown} disabled={!marker.moveDown}> <button onClick={marker.moveDown} disabled={isLast}>
🔽 🔽
</button> </button>
<button onClick={marker.remove}>🗑</button> <button onClick={marker.remove}>🗑</button>

@ -37,8 +37,13 @@ export const MarkersComponent = ({
<> <>
<h3>Markers</h3> <h3>Markers</h3>
<ol ref={listContainerRef}> <ol ref={listContainerRef}>
{markers.map((marker) => ( {markers.map((marker, i) => (
<MarkerComponent key={marker.key} marker={marker} /> <MarkerComponent
key={marker.key}
marker={marker}
isFirst={i === 0}
isLast={i === markers.length - 1}
/>
))} ))}
</ol> </ol>
</> </>

@ -3,8 +3,8 @@ import { Coordinates, Waypoint } from '../shared/types';
export type Marker = Waypoint & { export type Marker = Waypoint & {
key: string; key: string;
remove: () => void; remove: () => void;
moveUp?: () => void; moveUp: () => void;
moveDown?: () => void; moveDown: () => void;
label: string; label: string;
}; };
@ -49,4 +49,6 @@ export type ExportProps = {
export type MarkerProps = { export type MarkerProps = {
marker: Marker; marker: Marker;
isFirst: boolean;
isLast: boolean;
}; };

Loading…
Cancel
Save