From 664580f272d978ece9a1889e91c16bd084bdb1a0 Mon Sep 17 00:00:00 2001
From: Kai Reinhard <K.Reinhard@micromata.de>
Date: Fri, 25 Jan 2019 07:27:24 +0000
Subject: [PATCH] react-cookies for persisting file filter (not yet finished).

---
 borgbutler-webapp/src/components/views/archives/FileListPanel.jsx |   59 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/borgbutler-webapp/src/components/views/archives/FileListPanel.jsx b/borgbutler-webapp/src/components/views/archives/FileListPanel.jsx
index c040d14..b73031c 100644
--- a/borgbutler-webapp/src/components/views/archives/FileListPanel.jsx
+++ b/borgbutler-webapp/src/components/views/archives/FileListPanel.jsx
@@ -1,4 +1,5 @@
 import React from 'react'
+import cookie from "react-cookies";
 import {withRouter} from 'react-router-dom';
 import {Breadcrumb, Button} from 'reactstrap';
 import {getRestServiceUrl} from '../../../utilities/global';
@@ -10,34 +11,43 @@
 
 class FileListPanel extends React.Component {
 
-    state = {
-        isFetching: false, activeTab: '1',
-        fileList: undefined,
-        filter: {
-            search: '',
-            mode: 'tree',
-            currentDirectory: '',
-            maxSize: '50',
-            diffArchiveId: '',
-            autoChangeDirectoryToLeafItem: true,
-            openDownloads: true
-        }
-    };
-
     constructor(props) {
         super(props);
 
         this.fetchArchiveFileList = this.fetchArchiveFileList.bind(this);
         this.handleURLChange = this.handleURLChange.bind(this);
+        this.componentWillMount = this.componentWillMount.bind(this);
 
         this.unregisterHistoryListener = props.history.listen(this.handleURLChange);
-
+        this.state = {
+            isFetching: false, activeTab: '1',
+            fileList: undefined,
+            filter: {
+                search: '',
+                mode: 'tree',
+                currentDirectory: '',
+                maxSize: '50',
+                diffArchiveId: '',
+                autoChangeDirectoryToLeafItem: true,
+                openDownloads: true
+            }
+        };
         // Resetting the NoReFetch State
         if (props.location.state) {
             props.location.state.noReFetch = undefined;
         }
     }
 
+    componentWillMount = () => {
+        ['mode', 'maxSize', 'autoChangeDirectoryToLeafItem', 'openDownloads'].forEach(function (variable) {
+            const value = cookie.load(`file-list-${variable}`);
+            if (value) {
+                //console.log('Restoring ' + variable + '=' + value);
+                //this.setState({filter: {...this.state.filter, variable: value}});
+            }
+        });
+    }
+
     componentDidMount = () => {
         this.handleURLChange(this.props.location);
     };
@@ -57,20 +67,29 @@
 
     handleInputChange = (event, callback) => {
         event.preventDefault();
-        let target = event.target.name;
+        const variable = event.target.name;
         this.setState({filter: {...this.state.filter, [event.target.name]: event.target.value}},
             () => {
-                if (target === 'mode') {
+                if (variable === 'mode') {
                     this.fetchArchiveFileList();
                 }
                 if (callback) {
                     callback();
                 }
             });
+        if (['mode', 'maxSize'].indexOf(variable) >= 0) {
+            //console.log('Saving ' + variable + '=' + event.target.value);
+            cookie.save(`file-list-${variable}`, event.target.value, {path: "/"});
+        }
     };
 
     handleCheckboxChange = event => {
-        this.setState({filter: {...this.state.filter, [event.target.name]: event.target.checked}});
+        const variable = event.target.name;
+        this.setState({filter: {...this.state.filter, [variable]: event.target.checked}});
+        if (['autoChangeDirectoryToLeafItem', 'openDownloads'].indexOf(variable)) {
+            //console.log('Saving ' + variable + '=' + event.target.checked);
+            cookie.save(`file-list-${variable}`, event.target.checked, {path: "/"});
+        }
     }
 
     changeCurrentDirectory = (currentDirectory) => {
@@ -134,7 +153,7 @@
         let content = undefined;
 
         if (this.state.isFetching) {
-            content = <JobMonitorPanel repo={this.props.repoId} />;
+            content = <JobMonitorPanel repo={this.props.repoId}/>;
         } else if (this.state.failed) {
             content = <ErrorAlert
                 title={'Cannot load Archive file list'}
@@ -155,7 +174,7 @@
                 if (this.state.filter.mode === 'tree' && this.state.filter.currentDirectory.length > 0) {
                     breadcrumb = (
                         <Breadcrumb>
-                            <BreadcrumbPath match={this.props.match} />
+                            <BreadcrumbPath match={this.props.match}/>
                         </Breadcrumb>
                     );
                 }

--
Gitblit v1.10.0