-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
front/src/applications/editor/tools/pointEdition/CustomPosition.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { WidgetProps } from '@rjsf/core'; | ||
import InputSNCF from 'common/BootstrapSNCF/InputSNCF'; | ||
import { Point } from 'geojson'; | ||
import { TrackSectionEntity } from 'types'; | ||
import { calculateDistanceAlongTrack } from './tool-factory'; | ||
|
||
export const CustomPosition: React.FC< | ||
WidgetProps & { value?: number; track: TrackSectionEntity; point: Point } | ||
> = (props) => { | ||
const { schema, onChange, title, value, track, point } = props; | ||
const [, setLocalDistance] = useState(value); | ||
const POINT_NAME = 'point-parameter'; | ||
|
||
useEffect(() => { | ||
if (track && point) { | ||
const calculatedDistance = calculateDistanceAlongTrack(track, point); | ||
setLocalDistance(calculatedDistance); | ||
} | ||
}, [track, point]); | ||
const handleInputChange = (e: any) => { | ||
const newDistance = e.target.value; | ||
setLocalDistance(newDistance); | ||
onChange(newDistance); | ||
}; | ||
|
||
return ( | ||
<div key={`${POINT_NAME}-${schema.description}`}> | ||
<p>{title}</p> | ||
<InputSNCF | ||
name={POINT_NAME} | ||
id={`${POINT_NAME}-${schema.description}`} | ||
value={value} | ||
onChange={handleInputChange} | ||
type="number" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CustomPosition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters