browserState.ts 1.88 KB
Newer Older
1 2 3 4 5 6
export enum BrowserOpenState {
  EXPANDED = 'expanded',
  SEMI_EXPANDED = 'semiExpanded',
  COLLAPSED = 'collapsed'
}

7 8 9 10 11 12 13 14 15 16
// states are top, right, bottom, left (TRBL) and minus (zoom out) and plus (zoom in)
export type BrowserNavStates = [
  boolean,
  boolean,
  boolean,
  boolean,
  boolean,
  boolean
];

17 18
export type ChrLocation = [string, number, number];

19
export type BrowserState = Readonly<{
20
  browserActivated: boolean;
21
  browserNavOpened: boolean;
22
  browserNavStates: BrowserNavStates;
23
  browserOpenState: BrowserOpenState;
24
  chrLocation: ChrLocation;
25
  defaultChrLocation: ChrLocation;
26
  drawerOpened: boolean;
27
  drawerView: string;
28
  genomeSelectorActive: boolean;
29 30
  trackPanelModalOpened: boolean;
  trackPanelModalView: string;
31 32 33 34
  trackPanelOpened: boolean;
}>;

export const defaultState: BrowserState = {
35
  browserActivated: false,
36
  browserNavOpened: false,
37
  browserNavStates: [true, true, true, true, true, true],
38
  browserOpenState: BrowserOpenState.SEMI_EXPANDED,
39
  chrLocation: ['13', 0, 0],
40
  defaultChrLocation: ['13', 0, 0],
41
  drawerOpened: false,
42
  drawerView: '',
43
  genomeSelectorActive: false,
44 45
  trackPanelModalOpened: false,
  trackPanelModalView: '',
46 47 48
  trackPanelOpened: true
};

49 50 51 52
export const trackPanelState = (
  state: BrowserState,
  trackPanelOpened: boolean = !state.trackPanelOpened
) => {
53 54 55 56 57 58 59 60 61 62 63
  const browserOpenState: BrowserOpenState = trackPanelOpened
    ? BrowserOpenState.SEMI_EXPANDED
    : BrowserOpenState.EXPANDED;

  return {
    ...state,
    browserOpenState,
    trackPanelOpened
  };
};

64 65 66 67
export const drawerState = (
  state: BrowserState,
  drawerOpened: boolean = !state.drawerOpened
) => {
68 69 70 71 72 73 74 75
  if (drawerOpened === true) {
    return {
      ...state,
      browserOpenState: BrowserOpenState.COLLAPSED,
      drawerOpened
    };
  } else {
    return {
76 77 78 79
      ...state,
      browserOpenState: BrowserOpenState.SEMI_EXPANDED,
      drawerOpened,
      drawerView: ''
80 81 82
    };
  }
};