From ad8556a2d8face8dc2abaa688c2973abfcb250f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=A1=BA=E5=BC=BA?= Date: Sat, 23 Feb 2019 11:59:26 +0800 Subject: [PATCH] Dir view mode bug repair (#2988) * repair history go back bug * repair switch mode bug * add Comment --- .../src/pages/lib-content-view/lib-content-view.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/lib-content-view/lib-content-view.js b/frontend/src/pages/lib-content-view/lib-content-view.js index 679d814c65..6986b37cfb 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -78,6 +78,7 @@ class LibContentView extends React.Component { window.onpopstate = this.onpopstate; this.lastModifyTime = new Date(); + this.isNeedUpdateHistoryState = true; // Load, refresh page, switch mode for the first time, no need to set historyState } componentWillMount() { @@ -122,6 +123,8 @@ class LibContentView extends React.Component { let path = location.slice(location.indexOf(repoID) + repoID.length + 1); // get the string after repoID path = path.slice(path.indexOf('/')); // get current path + this.isNeedUpdateHistoryState = false; + this.setState({path: path}); if (!res.data.lib_need_decrypt) { @@ -286,8 +289,12 @@ class LibContentView extends React.Component { }); // update data - this.loadDirentList(repoID, path); + this.loadDirentList(path); + if (!this.isNeedUpdateHistoryState) { + this.isNeedUpdateHistoryState = true; + return; + } // update location let repoInfo = this.state.currentRepoInfo; let url = siteRoot + 'library/' + repoID + '/' + encodeURIComponent(repoInfo.repo_name) + Utils.encodePath(path); @@ -338,7 +345,8 @@ class LibContentView extends React.Component { window.history.pushState({url: url, path: filePath}, filePath, url); } - loadDirentList = (repoID, path) => { + loadDirentList = (path) => { + let repoID = this.props.repoID seafileAPI.listDir(repoID, path, {'with_thumbnail': true}).then(res => { let direntList = []; let markdownItem = null; @@ -522,7 +530,7 @@ class LibContentView extends React.Component { if (mode === 'column') { this.loadSidePanel(this.state.path); } - + this.isNeedUpdateHistoryState = false; this.setState({currentMode: mode}); this.showDir(path); }