Skip to content

Commit

Permalink
appease eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
gislawill committed Jul 1, 2024
1 parent 0c08e8c commit d902875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const CompositeLayer = ({ layer, before }: Props) => {
layer.dateLayer,
layer.expectedDataLagDays,
);
console.log('selectedDate', selectedDate);
const serverAvailableDates = useSelector(availableDatesSelector);
const opacityState = useSelector(opacitySelector(layer.id));
const dispatch = useDispatch();
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/utils/useDefaultDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDispatch, useSelector } from 'react-redux';
import { useEffect, useMemo } from 'react';
import { isMainLayer, LayerKey } from 'config/types';
import { DateItem, isMainLayer, LayerKey } from 'config/types';
import { availableDatesSelector } from 'context/serverStateSlice';
import {
dateRangeSelector,
Expand Down Expand Up @@ -35,13 +35,15 @@ export function useDefaultDate(
new Date().getTime() - (expectedDataLagDays ?? 0) * 24 * 60 * 60 * 1000;

const defaultDate = useMemo(() => {
let index = possibleDates?.length - 1;
let defaultDate = possibleDates?.[index]?.displayDate;
while (defaultDate && defaultDate > soonestAvailableDate) {
index -= 1;
defaultDate = possibleDates?.[index]?.displayDate;
}
return defaultDate;
return possibleDates?.reduceRight(
(acc: number | undefined, date: DateItem) => {
if (!acc && date.displayDate <= soonestAvailableDate) {
return date.displayDate;
}
return acc;
},
undefined,
);
}, [possibleDates, soonestAvailableDate]);

// React doesn't allow updating other components within another component
Expand Down

0 comments on commit d902875

Please sign in to comment.