Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
anisometropie committed Feb 11, 2025
1 parent 95549e8 commit f01cdb4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState, useTransition } from 'react';

import type { ProjectPathTrainResult, Waypoint } from '@osrd-project/ui-manchette/dist/types';
import type {
SpaceScale,
SpaceTimeChartProps,
} from '@osrd-project/ui-spacetimechart/dist/lib/types';

import usePaths from './usePaths';
import computePaths from './usePaths';
import { MAX_ZOOM_Y, MIN_ZOOM_Y, ZOOM_Y_DELTA, DEFAULT_ZOOM_MS_PER_PX } from '../consts';
import {
computeWaypointsToDisplay,
Expand Down Expand Up @@ -39,6 +39,7 @@ const useManchettesWithSpaceTimeChart = (
height = 561,
spaceTimeChartRef?: React.RefObject<HTMLDivElement>
) => {
const [loading, startTransition] = useTransition();

Check warning on line 42 in ui-manchette-with-spacetimechart/src/hooks/useManchetteWithSpaceTimeChart.ts

View workflow job for this annotation

GitHub Actions / build

'loading' is assigned a value but never used

Check warning on line 42 in ui-manchette-with-spacetimechart/src/hooks/useManchetteWithSpaceTimeChart.ts

View workflow job for this annotation

GitHub Actions / build

'loading' is assigned a value but never used
const [isShiftPressed, setIsShiftPressed] = useState(false);
const [state, setState] = useState<State>({
xZoom: timeScaleToZoomValue(DEFAULT_ZOOM_MS_PER_PX),
Expand All @@ -54,7 +55,13 @@ const useManchettesWithSpaceTimeChart = (

const { xZoom, yZoom, xOffset, yOffset, scrollTo, panning, isProportional } = state;

const paths = usePaths(projectPathTrainResult, selectedTrain);
const [paths, setPaths] = useState(() => computePaths(projectPathTrainResult, selectedTrain));
useEffect(() => {
console.log('transition');

Check warning on line 60 in ui-manchette-with-spacetimechart/src/hooks/useManchetteWithSpaceTimeChart.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 60 in ui-manchette-with-spacetimechart/src/hooks/useManchetteWithSpaceTimeChart.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
startTransition(() => {
setPaths(computePaths(projectPathTrainResult, selectedTrain));
});
}, [projectPathTrainResult, selectedTrain]);

const waypointsToDisplay = useMemo(
() => computeWaypointsToDisplay(waypoints, { height, isProportional, yZoom }),
Expand Down
37 changes: 16 additions & 21 deletions ui-manchette-with-spacetimechart/src/hooks/usePaths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable import/no-unresolved */
import { useMemo } from 'react';

import { type ProjectPathTrainResult } from '@osrd-project/ui-manchette/dist/types';
import { type PathLevel } from '@osrd-project/ui-spacetimechart';
Expand All @@ -12,25 +11,21 @@ const transformCurve = (curve: ProjectPathTrainResult['spaceTimeCurves'][0], dep
position,
}));

const usePaths = (projectPathTrainResult: ProjectPathTrainResult[], selectedTrain?: number) =>
useMemo(
() =>
projectPathTrainResult.flatMap((path) =>
path.spaceTimeCurves.map<{
id: string;
label: string;
color: string;
level: PathLevel;
points: { time: number; position: number }[];
}>((spaceTimeCurve, ind) => ({
id: `${path.id}-${ind}`,
label: path.name,
color: PATH_COLOR_DEFAULT,
level: selectedTrain && selectedTrain === path.id ? 1 : 2,
points: transformCurve(spaceTimeCurve, path.departureTime),
}))
),
[projectPathTrainResult, selectedTrain]
const computePaths = (projectPathTrainResult: ProjectPathTrainResult[], selectedTrain?: number) =>
projectPathTrainResult.flatMap((path) =>
path.spaceTimeCurves.map<{
id: string;
label: string;
color: string;
level: PathLevel;
points: { time: number; position: number }[];
}>((spaceTimeCurve, ind) => ({
id: `${path.id}-${ind}`,
label: path.name,
color: PATH_COLOR_DEFAULT,
level: selectedTrain && selectedTrain === path.id ? 1 : 2,
points: transformCurve(spaceTimeCurve, path.departureTime),
}))
);

export default usePaths;
export default computePaths;
5 changes: 3 additions & 2 deletions ui-manchette/src/components/Manchette.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useLayoutEffect, useRef, useState } from 'react';
import React, { memo, useLayoutEffect, useRef, useState } from 'react';

import { ZoomIn, ZoomOut } from '@osrd-project/ui-icons';
import cx from 'classnames';
Expand Down Expand Up @@ -50,6 +50,7 @@ const Manchette = ({

return (
<div className="manchette-container">
MANCHETTE
{waypointMenuData?.menu && waypointMenuData.activeWaypointId && (
<div className="menu-wrapper" style={{ top: menuPosition }}>
{waypointMenuData.menu}
Expand Down Expand Up @@ -105,4 +106,4 @@ const Manchette = ({
);
};

export default Manchette;
export default memo(Manchette);
7 changes: 4 additions & 3 deletions ui-spacetimechart/src/components/SpaceTimeChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useMemo, useState, memo } from 'react';

import cx from 'classnames';

Expand Down Expand Up @@ -29,7 +29,7 @@ import {
} from '../utils/scales';
import { snapPosition } from '../utils/snapping';

export const SpaceTimeChart = (props: SpaceTimeChartProps) => {
export const SpaceTimeChart = memo((props: SpaceTimeChartProps) => {

Check warning on line 32 in ui-spacetimechart/src/components/SpaceTimeChart.tsx

View workflow job for this annotation

GitHub Actions / build

Component definition is missing display name

Check warning on line 32 in ui-spacetimechart/src/components/SpaceTimeChart.tsx

View workflow job for this annotation

GitHub Actions / build

Component definition is missing display name
const {
operationalPoints,
spaceOrigin,
Expand Down Expand Up @@ -198,6 +198,7 @@ export const SpaceTimeChart = (props: SpaceTimeChartProps) => {
className={cx('relative space-time-chart', attr.className)}
style={{ background: fullTheme.background }}
>
SPACE_TIME
<div ref={setCanvasesRoot} className="absolute inset-0" />
<SpaceTimeChartContext.Provider value={contextState}>
<CanvasContext.Provider value={canvasContext}>
Expand All @@ -215,4 +216,4 @@ export const SpaceTimeChart = (props: SpaceTimeChartProps) => {
</SpaceTimeChartContext.Provider>
</div>
);
};
});
1 change: 1 addition & 0 deletions ui-speedspacechart/src/components/SpeedSpaceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const SpeedSpaceChart = ({
}}
tabIndex={0}
>
SPEED_SPACE
<div
className="flex justify-end absolute base-margin-top"
style={{ width: adjustedWidthRightAxis }}
Expand Down

0 comments on commit f01cdb4

Please sign in to comment.