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

save sidebarContentsId to localStorage

Yuki Takei 5 лет назад
Родитель
Сommit
28ef1718c9

+ 5 - 1
src/client/js/components/Sidebar/CustomSidebar.jsx

@@ -27,6 +27,7 @@ const CustomSidebar = (props) => {
   const { appContainer } = props;
   const { apiGet } = appContainer;
 
+  const [isMounted, setMounted] = useState(false);
   const [markdown, setMarkdown] = useState();
 
   const growiRenderer = appContainer.getRenderer('sidebar');
@@ -42,6 +43,9 @@ const CustomSidebar = (props) => {
       logger.warn(e.message);
       return;
     }
+    finally {
+      setMounted(true);
+    }
 
     setMarkdown(page.revision.body);
   }, [apiGet]);
@@ -58,7 +62,7 @@ const CustomSidebar = (props) => {
           <i className="icon icon-reload"></i>
         </button>
       </div>
-      { markdown == null && <SidebarNotFound /> }
+      { isMounted && markdown == null && <SidebarNotFound /> }
       {/* eslint-disable-next-line react/no-danger */}
       { markdown != null && (
         <div className="p-3">

+ 1 - 1
src/client/js/components/Sidebar/SidebarNav.jsx

@@ -23,7 +23,7 @@ class SidebarNav extends React.Component {
       onItemSelected(contentsId);
     }
 
-    navigationContainer.setState({ sidebarContentsId: contentsId });
+    navigationContainer.selectSidebarContents(contentsId);
   }
 
   PrimaryItem = ({ id, label, iconName }) => {

+ 6 - 1
src/client/js/services/NavigationContainer.js

@@ -31,7 +31,7 @@ export default class NavigationContainer extends Container {
       isDrawerMode: null,
       isDrawerOpened: false,
 
-      sidebarContentsId: 'recent',
+      sidebarContentsId: localStorage.sidebarContentsId || 'recent',
 
       isScrollTop: true,
 
@@ -190,6 +190,11 @@ export default class NavigationContainer extends Container {
     this.setState({ isDrawerMode, isDrawerOpened });
   }
 
+  selectSidebarContents(contentsId) {
+    window.localStorage.setItem('sidebarContentsId', contentsId);
+    this.setState({ sidebarContentsId: contentsId });
+  }
+
   openPageCreateModal() {
     if (this.appContainer.currentUser == null) {
       logger.warn('Please login or signup to create a new page.');