Commit 24249ddf authored by Aron Fiechter's avatar Aron Fiechter
Browse files

Use static min and max years from config

parent f23bf927
import React, { useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { setRange, setYears, selectYears, selectYearsMinMax } from './yearRangeSlice';
import { setRange, setYears, selectYears } from './yearRangeSlice';
import ReactEcharts from 'echarts-for-react';
import { selectNodes, selectResultsById } from '../navbar/querySlice';
import { useDebouncedCallback } from 'use-debounce';
import config from '../../config';
export default function YearRange() {
const dispatch = useDispatch();
......@@ -12,7 +13,6 @@ export default function YearRange() {
const nodes = useSelector(selectNodes);
const resultsById = useSelector(selectResultsById);
const years = useSelector(selectYears);
const { min, max } = useSelector(selectYearsMinMax);
const chartRef = useRef(null);
......@@ -38,9 +38,8 @@ export default function YearRange() {
const chart = chartRef.current.getEchartsInstance();
chart.on('datazoom', function () {
const axis = chart.getModel().option.xAxis[0];
console.log(min, max);
const start = axis.data[axis.rangeStart] || min;
const end = axis.data[axis.rangeEnd] || max;
const start = axis.data[axis.rangeStart] || config.YEARS.MIN;
const end = axis.data[axis.rangeEnd] || config.YEARS.MAX;
debouncedDispatch(setRange({ start, end }));
});
});
......
import { createSlice } from '@reduxjs/toolkit';
import config from '../../config';
export const yearRangeSlice = createSlice({
name: 'yearRange',
initialState: {
range: {
start: 1000,
end: 9999,
start: config.YEARS.MIN,
end: config.YEARS.MAX,
},
years: [],
},
......@@ -27,9 +28,5 @@ export const { setRange, setYears } = yearRangeSlice.actions;
export const selectYears = (state) => state.yearRange.years;
export const selectRange = (state) => state.yearRange.range;
export const selectYearsMinMax = (state) => {
const years = state.yearRange.years?.x || [1000, 9999];
return { min: Math.min(...years), max: Math.max(...years) };
};
export default yearRangeSlice.reducer;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment