Skip to content

Commit d5b152a

Browse files
committed
fixup! front: update stdcm simulation progress button design
1 parent 803027e commit d5b152a

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx

+2-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { compact } from 'lodash';
77
import { useTranslation } from 'react-i18next';
88
import { useSelector } from 'react-redux';
99

10-
import { LOADER_HEIGHT } from 'applications/stdcm/consts';
1110
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
1211
import useInfraStatus from 'modules/pathfinding/hooks/useInfraStatus';
1312
import { Map } from 'modules/trainschedule/components/ManageTrainSchedule';
@@ -20,7 +19,7 @@ import StdcmDestination from './StdcmDestination';
2019
import StdcmLinkedPathSearch from './StdcmLinkedPathSearch';
2120
import StdcmOrigin from './StdcmOrigin';
2221
import useStaticPathfinding from '../../hooks/useStaticPathfinding';
23-
import type { LoaderStatus, StdcmConfigErrors } from '../../types';
22+
import type { StdcmConfigErrors } from '../../types';
2423
import StdcmSimulationParams from '../StdcmSimulationParams';
2524
import StdcmVias from './StdcmVias';
2625
import { ArrivalTimeTypes, StdcmConfigErrorTypes } from '../../types';
@@ -79,23 +78,9 @@ const StdcmConfig = ({
7978
const pathfinding = useStaticPathfinding(infra);
8079

8180
const [formErrors, setFormErrors] = useState<StdcmConfigErrors>();
82-
const [loaderStatus, setLoaderStatus] = useState<LoaderStatus>();
8381

8482
const disabled = isPending || retainedSimulationIndex > -1;
8583

86-
useEffect(() => {
87-
if (!isPending || !launchButtonRef.current) {
88-
setLoaderStatus(undefined);
89-
} else {
90-
const { top } = launchButtonRef.current.getBoundingClientRect();
91-
const windowHeight = window.innerHeight;
92-
setLoaderStatus({
93-
status: windowHeight - top - 32 > LOADER_HEIGHT ? 'absolute' : 'fixedBottom',
94-
firstLaunch: true,
95-
});
96-
}
97-
}, [isPending]);
98-
9984
const startSimulation = () => {
10085
const isPathfindingFailed = !!pathfinding && pathfinding.status !== 'success';
10186
const formErrorsStatus = checkStdcmConfigErrors(
@@ -212,11 +197,9 @@ const StdcmConfig = ({
212197
)}
213198
</div>
214199

215-
{loaderStatus && (
200+
{isPending && (
216201
<StdcmLoader
217202
cancelStdcmRequest={cancelStdcmRequest}
218-
loaderStatus={loaderStatus}
219-
setLoaderStatus={setLoaderStatus}
220203
launchButtonRef={launchButtonRef}
221204
/>
222205
)}

front/src/applications/stdcm/components/StdcmLoader.tsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
import { useEffect, useRef, type RefObject } from 'react';
1+
import { useEffect, useRef, useState, type RefObject } from 'react';
22

33
import { Button } from '@osrd-project/ui-core';
44
import cx from 'classnames';
55
import { useTranslation } from 'react-i18next';
66

7-
import { LOADER_HEIGHT } from '../consts';
87
import type { LoaderStatus } from '../types';
98

9+
const LOADER_HEIGHT = 176;
1010
const LOADER_BOTTOM_OFFSET = 32;
1111
const FORM_TOP_OFFSET = 120 + 68; // navbar + prev path heights
1212
const LAUNCH_BUTTON_HEIGHT = 40;
1313

1414
type StdcmLoaderProps = {
1515
cancelStdcmRequest: () => void;
16-
loaderStatus: LoaderStatus;
17-
setLoaderStatus: (loaderStatus?: LoaderStatus) => void;
1816
launchButtonRef: RefObject<HTMLDivElement>;
1917
};
2018

21-
const StdcmLoader = ({
22-
cancelStdcmRequest,
23-
loaderStatus,
24-
setLoaderStatus,
25-
launchButtonRef,
26-
}: StdcmLoaderProps) => {
19+
const StdcmLoader = ({ cancelStdcmRequest, launchButtonRef }: StdcmLoaderProps) => {
2720
const { t } = useTranslation('stdcm');
2821
const loaderRef = useRef<HTMLDivElement>(null);
2922

23+
const { top } = launchButtonRef.current!.getBoundingClientRect();
24+
const windowHeight = window.innerHeight;
25+
26+
const [loaderStatus, setLoaderStatus] = useState<LoaderStatus>({
27+
status: windowHeight - top - 32 > LOADER_HEIGHT ? 'absolute' : 'fixedBottom',
28+
firstLaunch: true,
29+
});
30+
3031
useEffect(() => {
3132
// Depending on the scroll, change the position of the loader between fixed, sticky or absolute
3233
const handleScroll = () => {

front/src/applications/stdcm/consts.ts

-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ export const COMPOSITION_CODES = [
2222
];
2323

2424
export const DEFAULT_TOLERANCE = 1800; // 30min
25-
26-
export const LOADER_HEIGHT = 176;

0 commit comments

Comments
 (0)