use Slider for lookback period
parent
4d989f10eb
commit
c83f2ce0a0
@ -0,0 +1,66 @@
|
||||
import TextField from "@mui/material/TextField";
|
||||
import {
|
||||
refreshcalendarExitPriceChartData,
|
||||
refreshSimilarCalendarPriceChartData,
|
||||
refreshStockPriceChartData,
|
||||
} from "./actions";
|
||||
import { lookbackPeriodEnd, lookbackPeriodStart } from "./state";
|
||||
import Slider from "@mui/material/Slider";
|
||||
|
||||
const handleLookbackPeriodChange = (
|
||||
e,
|
||||
[newLookbackPeriodStart, newLookbackPeriodEnd]: [number, number]
|
||||
) => {
|
||||
const [lookbackPeriodStartUnixTime, lookbackPeriodEndUnixTime] = [
|
||||
new Date(lookbackPeriodStart.value).getTime(),
|
||||
new Date(lookbackPeriodEnd.value).getTime(),
|
||||
];
|
||||
if (lookbackPeriodStartUnixTime !== newLookbackPeriodStart) {
|
||||
lookbackPeriodStart.value = new Date(newLookbackPeriodStart)
|
||||
.toISOString()
|
||||
.substring(0, 10);
|
||||
refreshStockPriceChartData();
|
||||
refreshSimilarCalendarPriceChartData();
|
||||
refreshcalendarExitPriceChartData();
|
||||
}
|
||||
if (lookbackPeriodEndUnixTime !== newLookbackPeriodEnd) {
|
||||
lookbackPeriodEnd.value = new Date(newLookbackPeriodEnd)
|
||||
.toISOString()
|
||||
.substring(0, 10);
|
||||
refreshStockPriceChartData();
|
||||
refreshSimilarCalendarPriceChartData();
|
||||
refreshcalendarExitPriceChartData();
|
||||
}
|
||||
};
|
||||
|
||||
const earliestDate = new Date("2022-03-07");
|
||||
const DAY = 1000 * 60 * 60 * 24;
|
||||
function addDays(date, days) {
|
||||
const result = new Date(date);
|
||||
result.setDate(result.getDate() + days);
|
||||
return result.toISOString().substring(0, 10);
|
||||
}
|
||||
function daysBetween(date1, date2) {
|
||||
return Math.round(Math.abs((date2.getTime() - date1.getTime()) / DAY));
|
||||
}
|
||||
export function EditableLookbackPeriod() {
|
||||
return (
|
||||
<Slider
|
||||
value={[
|
||||
new Date(lookbackPeriodStart.value).getTime(),
|
||||
new Date(lookbackPeriodEnd.value).getTime(),
|
||||
]}
|
||||
onChange={handleLookbackPeriodChange}
|
||||
valueLabelFormat={(unixTimeMs) =>
|
||||
new Date(unixTimeMs).toISOString().substring(0, 10)
|
||||
}
|
||||
getAriaValueText={(unixTimeMs) =>
|
||||
new Date(unixTimeMs).toISOString().substring(0, 10)
|
||||
}
|
||||
min={earliestDate.getTime()}
|
||||
max={earliestDate.getTime() + 250 * DAY}
|
||||
step={DAY}
|
||||
valueLabelDisplay="on"
|
||||
/>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue