|
1 |
| -import { useEffect, useMemo, useRef, useState } from 'react'; |
| 1 | +import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; |
2 | 2 |
|
3 | 3 | import { Button } from '@osrd-project/ui-core';
|
4 | 4 | import cx from 'classnames';
|
@@ -90,8 +90,12 @@ const StdcmConfig = ({
|
90 | 90 | const totalLength = useSelector(getTotalLength);
|
91 | 91 | const maxSpeed = useSelector(getMaxSpeed);
|
92 | 92 |
|
93 |
| - const pathfinding = useStaticPathfinding(infra); |
| 93 | + const [showMessage, setShowMessage] = useState(false); |
| 94 | + |
| 95 | + const { pathfinding, isPathFindingLoading } = useStaticPathfinding(infra); |
| 96 | + |
94 | 97 | const formRef = useRef<HTMLDivElement>(null);
|
| 98 | + const pathfindingBannerRef = useRef<HTMLDivElement>(null); |
95 | 99 |
|
96 | 100 | const [formErrors, setFormErrors] = useState<StdcmConfigErrors>();
|
97 | 101 |
|
@@ -145,6 +149,13 @@ const StdcmConfig = ({
|
145 | 149 | );
|
146 | 150 | };
|
147 | 151 |
|
| 152 | + const getStatusMessage = () => { |
| 153 | + if (isPathFindingLoading) { |
| 154 | + return t('pathfindingStatus.calculating'); |
| 155 | + } |
| 156 | + return t('pathfindingStatus.success'); |
| 157 | + }; |
| 158 | + |
148 | 159 | useEffect(() => {
|
149 | 160 | if (pathfinding) {
|
150 | 161 | const formErrorsStatus = checkStdcmConfigErrors(
|
@@ -177,6 +188,31 @@ const StdcmConfig = ({
|
177 | 188 | }
|
178 | 189 | }, []);
|
179 | 190 |
|
| 191 | + useEffect(() => { |
| 192 | + if (isPathFindingLoading) { |
| 193 | + setShowMessage(true); |
| 194 | + } |
| 195 | + |
| 196 | + if (pathfinding?.status === 'failure') { |
| 197 | + setShowMessage(false); |
| 198 | + } |
| 199 | + }, [isPathFindingLoading, pathfinding?.status]); |
| 200 | + |
| 201 | + useLayoutEffect(() => { |
| 202 | + const handleAnimationEnd = () => { |
| 203 | + setShowMessage(false); |
| 204 | + }; |
| 205 | + |
| 206 | + if (!showMessage || formErrors) { |
| 207 | + return undefined; |
| 208 | + } |
| 209 | + pathfindingBannerRef.current!.addEventListener('animationend', handleAnimationEnd); |
| 210 | + |
| 211 | + return () => { |
| 212 | + pathfindingBannerRef.current?.removeEventListener('animationend', handleAnimationEnd); |
| 213 | + }; |
| 214 | + }, [showMessage, formErrors]); |
| 215 | + |
180 | 216 | return (
|
181 | 217 | <div className="stdcm__body">
|
182 | 218 | {isDebugMode && (
|
@@ -238,6 +274,20 @@ const StdcmConfig = ({
|
238 | 274 | )}
|
239 | 275 | </div>
|
240 | 276 |
|
| 277 | + {!formErrors && showMessage && ( |
| 278 | + <div className="simulation-status-banner"> |
| 279 | + <div className="banner-content"> |
| 280 | + <div |
| 281 | + ref={pathfindingBannerRef} |
| 282 | + className={cx('pathFinding-status', { |
| 283 | + 'pathFinding-status-success': pathfinding?.status === 'success', |
| 284 | + })} |
| 285 | + > |
| 286 | + {getStatusMessage()} |
| 287 | + </div> |
| 288 | + </div> |
| 289 | + </div> |
| 290 | + )} |
241 | 291 | {isPending && (
|
242 | 292 | <StdcmLoader
|
243 | 293 | cancelStdcmRequest={cancelStdcmRequest}
|
|
0 commit comments