Просмотр исходного кода

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

Save Recent Changes Size to Local Storage
stevenfukase 4 лет назад
Родитель
Сommit
257d6cffc5
1 измененных файлов с 28 добавлено и 1 удалено
  1. 28 1
      src/client/js/components/Sidebar/RecentChanges.jsx

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

@@ -28,10 +28,18 @@ class RecentChanges extends React.Component {
 
   constructor(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);
   }
 
+  componentWillMount() {
+    this.retrieveSizePreferenceFromLocalStorage();
+  }
+
   async componentDidMount() {
     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 }) => {
     const dPagePath = new DevidedPagePath(page.path, false, true);
     const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);