sidebarPanelStore.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Reflux from 'reflux';
  2. import {SidebarPanelKey} from 'app/components/sidebar/types';
  3. import SidebarPanelActions from '../actions/sidebarPanelActions';
  4. type SidebarPanelStoreInterface = {
  5. activePanel: SidebarPanelKey | '';
  6. onActivatePanel(panel: SidebarPanelKey): void;
  7. onTogglePanel(panel: SidebarPanelKey): void;
  8. onHidePanel(): void;
  9. };
  10. const sidebarPanelStoreConfig: Reflux.StoreDefinition & SidebarPanelStoreInterface = {
  11. activePanel: '',
  12. init() {
  13. this.listenTo(SidebarPanelActions.activatePanel, this.onActivatePanel);
  14. this.listenTo(SidebarPanelActions.hidePanel, this.onHidePanel);
  15. this.listenTo(SidebarPanelActions.togglePanel, this.onTogglePanel);
  16. },
  17. onActivatePanel(panel: SidebarPanelKey) {
  18. this.activePanel = panel;
  19. this.trigger(this.activePanel);
  20. },
  21. onTogglePanel(panel: SidebarPanelKey) {
  22. if (this.activePanel === panel) {
  23. this.onHidePanel();
  24. } else {
  25. this.onActivatePanel(panel);
  26. }
  27. },
  28. onHidePanel() {
  29. this.activePanel = '';
  30. this.trigger(this.activePanel);
  31. },
  32. };
  33. type SidebarPanelStore = Reflux.Store & SidebarPanelStoreInterface;
  34. /**
  35. * This store is used to hold local user preferences
  36. * Side-effects (like reading/writing to cookies) are done in associated actionCreators
  37. */
  38. const SidebarPanelStore = Reflux.createStore(
  39. sidebarPanelStoreConfig
  40. ) as SidebarPanelStore;
  41. export default SidebarPanelStore;