Reduce visual transitions when updating delays

This commit is contained in:
Emmy D'Anello 2024-02-10 20:54:12 +01:00
parent 7486fb2b4d
commit 0e87ecd8cf
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 12 additions and 3 deletions

View File

@ -11,7 +11,7 @@ import {
} from "@mui/material" } from "@mui/material"
import {CSSTransition, TransitionGroup} from 'react-transition-group' import {CSSTransition, TransitionGroup} from 'react-transition-group'
import {useQueries, useQuery} from "@tanstack/react-query"; import {useQueries, useQuery} from "@tanstack/react-query";
import {useCallback, useEffect, useMemo, useRef} from "react"; import {useCallback, useEffect, useMemo, useRef, useState} from "react";
const StyledTableRow = styled(TableRow)(({ theme, tabletype }) => ({ const StyledTableRow = styled(TableRow)(({ theme, tabletype }) => ({
'tbody &:nth-of-type(odd)': { 'tbody &:nth-of-type(odd)': {
@ -140,7 +140,12 @@ function TrainRow({train, tableType, date, time}) {
.then(response => response.json()), .then(response => response.json()),
enabled: !!trip.id, enabled: !!trip.id,
}) })
const realtimeTripData = realtimeTripQuery.data ?? {}
const [realtimeTripData, setRealtimeTripData] = useState({})
useEffect(() => {
if (realtimeTripQuery.data)
setRealtimeTripData(realtimeTripQuery.data)
}, [realtimeTripQuery.data])
const tripScheduleRelationship = realtimeTripData.schedule_relationship ?? 0 const tripScheduleRelationship = realtimeTripData.schedule_relationship ?? 0
const realtimeQuery = useQuery({ const realtimeQuery = useQuery({
@ -149,7 +154,11 @@ function TrainRow({train, tableType, date, time}) {
.then(response => response.json()), .then(response => response.json()),
enabled: !!train.id, enabled: !!train.id,
}) })
const realtimeData = realtimeQuery.data ?? {} const [realtimeData, setRealtimeData] = useState({})
useEffect(() => {
if (realtimeQuery.data)
setRealtimeData(realtimeQuery.data)
}, [realtimeQuery.data])
const stopScheduleRelationship = realtimeData.schedule_relationship ?? 0 const stopScheduleRelationship = realtimeData.schedule_relationship ?? 0
const canceled = tripScheduleRelationship === 3 || stopScheduleRelationship === 1 const canceled = tripScheduleRelationship === 3 || stopScheduleRelationship === 1