From 82cf40b516b5ab11c34b3642a01603ec1b590c9f Mon Sep 17 00:00:00 2001
From: Jules Laplace <julescarbon@gmail.com>
Date: Thu, 29 Jun 2017 13:05:21 +0200
Subject: store open folders in localstorage

---
 client/components/App.jsx | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

(limited to 'client/components/App.jsx')

diff --git a/client/components/App.jsx b/client/components/App.jsx
index 0ed9288..85766e5 100644
--- a/client/components/App.jsx
+++ b/client/components/App.jsx
@@ -14,23 +14,36 @@ class App extends Component {
     super()
     let openFolders = JSON.parse( localStorage['openFolders'] || 'null' )
     this.state = {
-      folders: null,
+      folders: [],
       openFolders: openFolders || [],
     }
     client.folder.index().then( folders => this.setState({ folders }) )
   }
   openFolder(folder) {
-    if (this.state.openFolders.indexOf(folder) === -1) {
-      this.setState({ openFolders: this.state.openFolders.concat([folder]) })
+    if (this.state.openFolders.indexOf(folder.id) === -1) {
+      const newOpenFolders = this.state.openFolders.concat(folder.id)
+      localStorage['openFolders'] = JSON.stringify(newOpenFolders)
+      this.setState({ openFolders: newOpenFolders })
     }
   }
+  closeFolder(folder) {
+    const openFolders = this.state.openFolders.filter( folder_id => folder_id !== folder.id )
+    localStorage['openFolders'] = JSON.stringify(openFolders)
+    this.setState({ openFolders })
+  }
   addFolder(folder) {
     this.setState({ folders: this.state.folders.concat([folder]) })
   }
   render() {
-    const openFolders = this.state.openFolders.map((folder) => {
+    const openFolders = this.state.openFolders.map((folder_id) => {
+      const folder_list = this.state.folders.filter(folder => folder.id === folder_id)
+      if (! folder_list.length) return
+      const folder = folder_list[0]
       return (
-        <Folder folder={folder} />
+        <Folder
+          folder={folder}
+          onClose={() => this.closeFolder(folder)}
+        />
       )
     })
     return (
-- 
cgit v1.2.3-70-g09d2

