Commit ed04b92f authored by Aron Fiechter's avatar Aron Fiechter
Browse files

Use range as object with start and end props in yearRangeSlice

parent d642d227
......@@ -3,8 +3,10 @@ import { createSlice } from '@reduxjs/toolkit';
export const yearRangeSlice = createSlice({
name: 'yearRange',
initialState: {
start: 1000,
end: 9999,
range: {
start: 1000,
end: 9999,
},
years: [],
},
reducers: {
......@@ -12,11 +14,8 @@ export const yearRangeSlice = createSlice({
// doesn't actually mutate the state because it uses the Immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
setStart: (state, action) => {
state.start = action.payload;
},
setEnd: (state, action) => {
state.end = action.payload;
setRange: (state, action) => {
state.range = action.payload;
},
setYears: (state, action) => {
state.years = action.payload;
......@@ -24,12 +23,13 @@ export const yearRangeSlice = createSlice({
},
});
export const { setStart, setEnd, setYears } = yearRangeSlice.actions;
export const { setRange, setYears } = yearRangeSlice.actions;
export const selectYears = (state) => state.yearRange.years;
export const selectRange = (state) => ({
start: state.yearRange.start,
end: state.yearRange.end,
});
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