Skip to content

Commit

Permalink
put if statements in useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarcMilletScality committed May 23, 2024
1 parent b684938 commit 70018a3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/lib/components/globalhealthbar/HistorySlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormattedDateTime, Icon, spacing } from '../../index';
import { FocusVisibleStyle } from '../buttonv2/Buttonv2.component';
import { useHistoryAlert } from './HistoryProvider';
import { getStep, setHistoryTooltipPosition } from './utils';
import { useEffect } from 'react';

const StyledRange = styled.input`
width: 600px;
Expand Down Expand Up @@ -92,16 +93,21 @@ export const HistoryAlertSlider = ({
}: HistorySliderProps) => {
const history = useHistoryAlert();

// check in 1hour range : bug with input date going from 1:00 to 0:00
useEffect(() => {
if (history.selectedDate != null) {
if (history.selectedDate > endDate) {
history.setSelectedDate(endDate);
}
if (history.selectedDate < startDate) {
history.setSelectedDate(startDate);
}
}
}, [history.selectedDate, startDate, endDate]);

if (history.selectedDate === null) {
return null;
}
// check in 1hour range : bug with input date going from 1:00 to 0:00
if (history.selectedDate > endDate) {
history.setSelectedDate(endDate);
}
if (history.selectedDate < startDate) {
history.setSelectedDate(startDate);
}

return (
<HistoryContainer id="history-slider">
Expand Down

0 comments on commit 70018a3

Please sign in to comment.