@@ -8,10 +8,10 @@ import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
8
8
import { useOsrdConfSelectors } from 'common/osrdContext' ;
9
9
import { isEqualDate } from 'utils/date' ;
10
10
11
- import type { StdcmLinkedPathResult , StdcmLinkedPathStep } from '../types' ;
11
+ import type { StdcmLinkedTrainResult , StdcmLinkedPathStep } from '../types' ;
12
12
import computeOpSchedules from '../utils/computeOpSchedules' ;
13
13
14
- const useLinkedPathSearch = ( ) => {
14
+ const useLinkedTrainSearch = ( ) => {
15
15
const [ postSearch ] = osrdEditoastApi . endpoints . postSearch . useMutation ( ) ;
16
16
17
17
const { getTimetableID, getSearchDatetimeWindow } = useOsrdConfSelectors ( ) ;
@@ -31,8 +31,8 @@ const useLinkedPathSearch = () => {
31
31
const [ displaySearchButton , setDisplaySearchButton ] = useState ( true ) ;
32
32
const [ hasSearchBeenLaunched , setHasSearchBeenLaunched ] = useState ( false ) ;
33
33
const [ trainNameInput , setTrainNameInput ] = useState ( '' ) ;
34
- const [ linkedPathDate , setLinkedPathDate ] = useState ( selectableSlot . start ) ;
35
- const [ linkedPathResults , setLinkedPathResults ] = useState < StdcmLinkedPathResult [ ] > ( [ ] ) ;
34
+ const [ linkedTrainDate , setLinkedTrainDate ] = useState ( selectableSlot . start ) ;
35
+ const [ linkedTrainResults , setLinkedTrainResults ] = useState < StdcmLinkedTrainResult [ ] > ( [ ] ) ;
36
36
37
37
const getExtremitiesDetails = useCallback (
38
38
async ( pathItemList : PathItem [ ] ) => {
@@ -64,7 +64,7 @@ const useLinkedPathSearch = () => {
64
64
65
65
const launchTrainScheduleSearch = useCallback ( async ( ) => {
66
66
setDisplaySearchButton ( false ) ;
67
- setLinkedPathResults ( [ ] ) ;
67
+ setLinkedTrainResults ( [ ] ) ;
68
68
try {
69
69
const results = ( await postSearch ( {
70
70
searchPayload : {
@@ -78,15 +78,15 @@ const useLinkedPathSearch = () => {
78
78
pageSize : 25 ,
79
79
} ) . unwrap ( ) ) as SearchResultItemTrainSchedule [ ] ;
80
80
const filteredResults = results . filter ( ( result ) =>
81
- isEqualDate ( linkedPathDate , new Date ( result . start_time ) )
81
+ isEqualDate ( linkedTrainDate , new Date ( result . start_time ) )
82
82
) ;
83
83
84
84
if ( ! filteredResults . length ) {
85
85
setDisplaySearchButton ( true ) ;
86
86
return ;
87
87
}
88
88
89
- const newLinkedPathResults = await Promise . all (
89
+ const newLinkedTrainResults = await Promise . all (
90
90
filteredResults . map ( async ( result ) => {
91
91
const opDetails = await getExtremitiesDetails ( result . path ) ;
92
92
const computedOpSchedules = computeOpSchedules (
@@ -104,26 +104,26 @@ const useLinkedPathSearch = () => {
104
104
} ;
105
105
} )
106
106
) ;
107
- setLinkedPathResults ( compact ( newLinkedPathResults ) ) ;
107
+ setLinkedTrainResults ( compact ( newLinkedTrainResults ) ) ;
108
108
setHasSearchBeenLaunched ( true ) ;
109
109
} catch ( error ) {
110
110
console . error ( 'Train schedule search failed:' , error ) ;
111
111
setDisplaySearchButton ( true ) ;
112
112
}
113
- } , [ postSearch , trainNameInput , timetableId , linkedPathDate , getExtremitiesDetails ] ) ;
113
+ } , [ postSearch , trainNameInput , timetableId , linkedTrainDate , getExtremitiesDetails ] ) ;
114
114
115
115
return {
116
116
displaySearchButton,
117
117
hasSearchBeenLaunched,
118
118
launchTrainScheduleSearch,
119
- linkedPathDate ,
120
- linkedPathResults ,
119
+ linkedTrainDate ,
120
+ linkedTrainResults ,
121
121
selectableSlot,
122
122
setDisplaySearchButton,
123
- setLinkedPathDate ,
123
+ setLinkedTrainDate ,
124
124
setTrainNameInput,
125
125
trainNameInput,
126
126
} ;
127
127
} ;
128
128
129
- export default useLinkedPathSearch ;
129
+ export default useLinkedTrainSearch ;
0 commit comments