/ concept-collection / ephys_compression_tests
Sign in
concept-collection / ephys_compression_tests
ephys_compression_tests / web-ui / src / components / dataset / timeseriesViewReducer.ts
55 lines · 1.2 KBCodeBlameHistory
8d96984Update benchmark results from 2026-06-16 14:21:30 [skip ci]GitHub Actions Bot 1import { Range } from "./WorkerTypes";
3// State Type
4export interface TimeseriesViewState {
5 selectedIndex: number;
6 isDragging: boolean;
7 lastDragX: number;
8 xRange: Range;
9}
11// Initial State
12export const initialState: TimeseriesViewState = {
13 selectedIndex: -1,
14 isDragging: false,
15 lastDragX: 0,
16 xRange: { min: 0, max: 999 },
17};
19// Action Types Union
20type TimeseriesViewAction =
21 | { type: "SET_SELECTED_INDEX"; index: number }
22 | { type: "SET_IS_DRAGGING"; isDragging: boolean }
23 | { type: "SET_LAST_DRAG_X"; x: number }
24 | { type: "SET_X_RANGE"; range: Range };
26// Reducer
27export const timeseriesViewReducer = (
28 state: TimeseriesViewState = initialState,
29 action: TimeseriesViewAction,
30): TimeseriesViewState => {
31 switch (action.type) {
32 case "SET_SELECTED_INDEX":
33 return {
34 ...state,
35 selectedIndex: action.index,
36 };
37 case "SET_IS_DRAGGING":
38 return {
39 ...state,
40 isDragging: action.isDragging,
41 };
42 case "SET_LAST_DRAG_X":
43 return {
44 ...state,
45 lastDragX: action.x,
46 };
47 case "SET_X_RANGE":
48 return {
49 ...state,
50 xRange: action.range,
51 };
52 default:
53 return state;
54 }
55};
moveopenescclose