PageAccessoriesContainer.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. activeTab: '',
  36. });
  37. }
  38. switchActiveTab(activeTab) {
  39. this.setState({
  40. activeTab, activeComponents: this.state.activeComponents.add(activeTab),
  41. });
  42. }
  43. }