Browse Source

BugFix restore PageNode instance from cache

Yuki Takei 9 years ago
parent
commit
bd6855a6ff

+ 3 - 3
packages/growi-plugin-lsx/src/resource/js/components/Lsx.jsx

@@ -22,6 +22,9 @@ export class Lsx extends React.Component {
   }
 
   componentDidMount() {
+    const lsxContext = this.props.lsxContext;
+    lsxContext.parse();
+
     // check cache exists
     if (this.props.lsxStateCache) {
       this.setState({
@@ -33,9 +36,6 @@ export class Lsx extends React.Component {
       return;   // go to render()
     }
 
-    const lsxContext = this.props.lsxContext;
-    lsxContext.parse();
-
     let pagePath = lsxContext.pagePath;
 
     this.props.crowi.apiGet('/plugins/lsx', {pagePath, queryOptions: ''})

+ 12 - 0
packages/growi-plugin-lsx/src/resource/js/components/PageNode.js

@@ -30,4 +30,16 @@ export class PageNode {
       return child.getDecendantsGenerationsNum();
     }))
   }
+
+  static instanciateFrom(obj) {
+    let pageNode = new PageNode(obj.pagePath);
+    pageNode.page = obj.page;
+
+    // instanciate recursively
+    pageNode.children = obj.children.map((childObj) => {
+      return PageNode.instanciateFrom(childObj);
+    })
+
+    return pageNode
+  }
 }

+ 13 - 2
packages/growi-plugin-lsx/src/resource/js/util/LsxCacheHelper.js

@@ -1,3 +1,5 @@
+import { PageNode } from '../components/PageNode';
+
 export class LsxCacheHelper {
 
   /**
@@ -42,8 +44,17 @@ export class LsxCacheHelper {
    * @memberOf LsxCacheHelper
    */
   static getStateCache(key) {
-    let cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
-    return cacheObj[key];
+    const cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
+    const stateCache = cacheObj[key];
+
+    if (stateCache !== undefined) {
+      // instanciate PageNode
+      stateCache.nodeTree = stateCache.nodeTree.map((obj) => {
+        return PageNode.instanciateFrom(obj);
+      })
+    }
+
+    return stateCache;
   }
 
   /**