Улучшено отображение при переходе в архив

This commit is contained in:
Александр Сироткин 2022-11-21 10:58:02 +05:00
parent d56810700f
commit fe52116a9b

View File

@ -72,6 +72,8 @@ const makeSubjectSubsription = (subject$, handler) => {
return () => subscribtion.unsubscribe() return () => subscribtion.unsubscribe()
} }
const getRowDate = (row) => row && isRawDate(row.date) ? new Date(row.date) : null
const TelemetryView = memo(() => { const TelemetryView = memo(() => {
const [well, updateWell] = useWell() const [well, updateWell] = useWell()
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
@ -101,6 +103,10 @@ const TelemetryView = memo(() => {
const dataSaub = normalizeData(data) const dataSaub = normalizeData(data)
const out = replace ? [...dataSaub] : [...prev, ...dataSaub] const out = replace ? [...dataSaub] : [...prev, ...dataSaub]
out.sort(dateSorter) out.sort(dateSorter)
setLoadedDataRange({
start: getRowDate(out.at(0)),
end: getRowDate(out.at(-1)),
})
return out return out
}) })
}, []) }, [])
@ -116,8 +122,6 @@ const TelemetryView = memo(() => {
const onWheel = useCallback((e) => { const onWheel = useCallback((e) => {
if (!archiveMode && e.deltaY < 0) { if (!archiveMode && e.deltaY < 0) {
setArchiveMode(true) setArchiveMode(true)
setDataSaub([])
setDataSpin([])
} else if (archiveMode) { } else if (archiveMode) {
setEndDate((prevEndDate) => { setEndDate((prevEndDate) => {
const offset = e.deltaY / 100 * chartInterval * 0.15 // сдвиг в 15% интервала const offset = e.deltaY / 100 * chartInterval * 0.15 // сдвиг в 15% интервала
@ -127,7 +131,6 @@ const TelemetryView = memo(() => {
const out = new Date(Math.max(firstPossibleDate, Math.min(nextEndDate, lastPossibleDate))) const out = new Date(Math.max(firstPossibleDate, Math.min(nextEndDate, lastPossibleDate)))
if (e.deltaY > 0 && +out >= lastPossibleDate) { // Автопереход к актуальным данным при прокручивании в самый низ if (e.deltaY > 0 && +out >= lastPossibleDate) { // Автопереход к актуальным данным при прокручивании в самый низ
setArchiveMode(false) setArchiveMode(false)
setLoadedDataRange(null)
} }
return out return out
}) })
@ -209,7 +212,10 @@ const TelemetryView = memo(() => {
if (data) { if (data) {
data.forEach(elm => elm.date = new Date(elm.date)) data.forEach(elm => elm.date = new Date(elm.date))
setDataSaub((prevDataSaub) => { setDataSaub((prevDataSaub) => {
const newData = [...prevDataSaub, ...normalizeData(data)] let newData = normalizeData(data)
if (+loadingStartDate > +loadedDataRange.start || (+loadingStartDate + loadingInterval * 1000) < +loadedDataRange.end) {
newData = [...prevDataSaub, ...newData]
}
newData.sort(dateSorter) newData.sort(dateSorter)
return cutData(newData, loadedStartDate, loadedEndDate) return cutData(newData, loadedStartDate, loadedEndDate)
}) })