Przeglądaj źródła

Merge pull request #4192 from weseek/feat/6528-recent-changes-local-storage

Save Recent Changes Size to Local Storage
stevenfukase 4 lat temu
rodzic
commit
257d6cffc5

+ 28 - 1
src/client/js/components/Sidebar/RecentChanges.jsx

@@ -28,10 +28,18 @@ class RecentChanges extends React.Component {
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
-
+    this.state = {
+      // TODO: 7092 connect to state
+      // eslint-disable-next-line react/no-unused-state
+      isRecentChangesSidebarSmall: false,
+    };
     this.reloadData = this.reloadData.bind(this);
     this.reloadData = this.reloadData.bind(this);
   }
   }
 
 
+  componentWillMount() {
+    this.retrieveSizePreferenceFromLocalStorage();
+  }
+
   async componentDidMount() {
   async componentDidMount() {
     this.reloadData();
     this.reloadData();
   }
   }
@@ -48,6 +56,25 @@ class RecentChanges extends React.Component {
     }
     }
   }
   }
 
 
+  retrieveSizePreferenceFromLocalStorage() {
+    if (window.localStorage.isRecentChangesSidebarSmall === 'true') {
+      this.setState({
+        // TODO: 7092 connect to state
+        // eslint-disable-next-line react/no-unused-state
+        isRecentChangesSidebarSmall: true,
+      });
+    }
+  }
+
+  changeSizeHandler = (e) => {
+    this.setState({
+      // TODO: 7092 connect to state
+      // eslint-disable-next-line react/no-unused-state
+      isRecentChangesSidebarSmall: e.target.checked,
+    });
+    window.localStorage.setItem('isRecentChangesSidebarSmall', e.target.checked);
+  }
+
   PageItem = ({ page }) => {
   PageItem = ({ page }) => {
     const dPagePath = new DevidedPagePath(page.path, false, true);
     const dPagePath = new DevidedPagePath(page.path, false, true);
     const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
     const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);