PageAccessoriesContainer.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container related to options for Application
  4. * @extends {Container} unstated Container
  5. */
  6. export default class PageAccessoriesContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.state = {
  11. isPageAccessoriesModalShown: false,
  12. activeTab: '',
  13. // Prevent unnecessary rendering
  14. activeComponents: new Set(['']),
  15. };
  16. this.openPageAccessoriesModal = this.openPageAccessoriesModal.bind(this);
  17. this.closePageAccessoriesModal = this.closePageAccessoriesModal.bind(this);
  18. this.switchActiveTab = this.switchActiveTab.bind(this);
  19. }
  20. /**
  21. * Workaround for the mangling in production build to break constructor.name
  22. */
  23. static getClassName() {
  24. return 'PageAccessoriesContainer';
  25. }
  26. openPageAccessoriesModal(activeTab) {
  27. this.setState({
  28. isPageAccessoriesModalShown: true,
  29. });
  30. this.switchActiveTab(activeTab);
  31. }
  32. closePageAccessoriesModal() {
  33. this.setState({
  34. isPageAccessoriesModalShown: false,
  35. });
  36. }
  37. switchActiveTab(activeTab) {
  38. this.setState({
  39. activeTab, activeComponents: this.state.activeComponents.add(activeTab),
  40. });
  41. }
  42. }