Skip to content

Commit

Permalink
made timespan change to load data #209
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Aug 7, 2024
1 parent 3016d1e commit 37d3c44
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/states/SensorCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,30 @@ function SensorCompare(props) {

const loadButton = <Button isDisabled={!selectedSensors.length || loading} onClick={() => load()}>{i18next.t("load")}</Button>

const load = () => {
const load = (newFrom, newTo) => {
reloadIndex++
setViewData({ sensors: selectedSensors, from, to, dataKey, reloadIndex })
setViewData({ sensors: selectedSensors, from: newFrom || from, to: newTo || to, dataKey, reloadIndex })
if (newFrom && newTo) {
setFrom(newFrom)
setTo(newTo)
}
}

const updateDuration = (v) => {
setDurationPickerValue(v)
let setFromTo = null, setToTo = null
if (typeof v === "object") {
setFrom(v.from.getTime() / 1000)
setTo(v.to.getTime() / 1000)
setFromTo = v.from.getTime() / 1000
setToTo = v.to.getTime() / 1000
} else {
setFromTo = (new Date().getTime() / 1000) - 60 * 60 * v
setToTo = new Date().getTime() / 1000
}
if (viewData) {
load(setFromTo, setToTo)
} else {
setFrom((new Date().getTime() / 1000) - 60 * 60 * v)
setTo(new Date().getTime() / 1000)
setFrom(setFromTo)
setTo(setToTo)
}
}
const durationPicker = <DurationPicker value={durationPickerValue} onChange={v => updateDuration(v)} />
Expand Down

0 comments on commit 37d3c44

Please sign in to comment.