Yuki Takei 6 лет назад
Родитель
Сommit
d0a88a2d5f
1 измененных файлов с 23 добавлено и 14 удалено
  1. 23 14
      src/client/js/services/AdminCustomizeContainer.js

+ 23 - 14
src/client/js/services/AdminCustomizeContainer.js

@@ -103,26 +103,17 @@ export default class AdminCustomizeContainer extends Container {
   /**
    * Switch themeType
    */
-  async switchThemeType(themeName) {
+  switchThemeType(themeName) {
     // can't choose theme when kibela
     if (this.state.currentLayout === 'kibela') {
       return;
     }
-
-    let assetPath;
-    try {
-      // get theme asset path
-      const response = await this.appContainer.apiv3.get('/customize-setting/layout-theme/asset-path', { themeName });
-      assetPath = response.data.assetPath;
-    }
-    catch (err) {
-      toastError(err);
-    }
-
     this.setState({ currentTheme: themeName });
 
-    const themeLink = document.getElementById('grw-theme-link');
-    themeLink.setAttribute('href', assetPath);
+    // preview if production
+    if (process.env.NODE_ENV !== 'development') {
+      this.previewTheme(themeName);
+    }
   }
 
   /**
@@ -212,6 +203,24 @@ export default class AdminCustomizeContainer extends Container {
     this.setState({ currentCustomizeScript: inpuValue });
   }
 
+  /**
+   * Preview theme
+   * @param {string} themeName
+   */
+  async previewTheme(themeName) {
+    let assetPath;
+    try {
+      // get theme asset path
+      const response = await this.appContainer.apiv3.get('/customize-setting/layout-theme/asset-path', { themeName });
+      assetPath = response.data.assetPath;
+
+      const themeLink = document.getElementById('grw-theme-link');
+      themeLink.setAttribute('href', assetPath);
+    }
+    catch (err) {
+      toastError(err);
+    }
+  }
 
   /**
    * Update layout