AdminCustomizeContainer.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container for admin customize setting page (Customize.jsx)
  4. * @extends {Container} unstated Container
  5. */
  6. export default class AdminCustomizeContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.state = {
  11. currentTheme: appContainer.config.themeType,
  12. currentLayout: appContainer.config.layoutType,
  13. currentBehavior: appContainer.config.behaviorType,
  14. };
  15. this.switchLayoutType = this.switchLayoutType.bind(this);
  16. }
  17. /**
  18. * Workaround for the mangling in production build to break constructor.name
  19. */
  20. static getClassName() {
  21. return 'AdminCustomizeContainer';
  22. }
  23. /**
  24. * Switch layoutType
  25. */
  26. switchLayoutType(lauoutName) {
  27. this.setState({ currentLayout: lauoutName });
  28. }
  29. /**
  30. * Switch themeType
  31. */
  32. switchThemeType(themeName) {
  33. // can't choose theme when kibela
  34. if (this.state.currentLayout === 'kibela') {
  35. return;
  36. }
  37. this.setState({ currentTheme: themeName });
  38. }
  39. /**
  40. * Update layout
  41. * @memberOf AdminCustomizeContainer
  42. * @return {Array} Appearance
  43. */
  44. async updateCustomizeLayoutAndTheme() {
  45. const response = await this.appContainer.apiv3.put('/customize-setting/layoutTheme', {
  46. layoutType: this.state.currentLayout,
  47. themeType: this.state.currentTheme,
  48. });
  49. const { customizeParams } = response.data;
  50. return customizeParams;
  51. }
  52. }