1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 07:27:04 +00:00

wiki-init-bug (#2325)

* wiki-init-bug

* repair wiki init load bug

* add wiki file
This commit is contained in:
shanshuirenjia
2018-09-01 13:48:20 +08:00
committed by Daniel Pan
parent 4b97e41be2
commit 18b3b68ae5
4 changed files with 14 additions and 16 deletions

View File

@@ -147,7 +147,7 @@ class SidePanel extends Component {
let currentNode = this.state.currentNode; let currentNode = this.state.currentNode;
if (this.isModifyContainsCurrentFile()) { if (this.isModifyContainsCurrentFile()) {
let nodePath = currentNode.path; let nodePath = currentNode.path;
let filePath = _this.props.currentFileNode.path; let filePath = _this.props.currentFilePath;
let start = filePath.indexOf(nodePath); let start = filePath.indexOf(nodePath);
let node = currentNode.getNodeByPath(filePath.slice(start)); let node = currentNode.getNodeByPath(filePath.slice(start));
if (node) { if (node) {
@@ -199,12 +199,14 @@ class SidePanel extends Component {
isModifyCurrentFile() { isModifyCurrentFile() {
let nodeName = this.state.currentNode.name; let nodeName = this.state.currentNode.name;
let fileName = this.props.currentFileNode.name; let filePath = this.props.currentFilePath;
let index = filePath.lastIndexOf("/");
let fileName = filePath.slice(index+1);
return nodeName === fileName; return nodeName === fileName;
} }
isModifyContainsCurrentFile() { isModifyContainsCurrentFile() {
let filePath = this.props.currentFileNode.path; let filePath = this.props.currentFilePath;
let nodePath = this.state.currentNode.path; let nodePath = this.state.currentNode.path;
if (filePath.indexOf(nodePath) > -1) { if (filePath.indexOf(nodePath) > -1) {
@@ -250,7 +252,6 @@ class SidePanel extends Component {
componentDidMount() { componentDidMount() {
//init treeview data //init treeview data
this.initializeTreeData(); this.initializeTreeData();
document.addEventListener('click', this.onHideContextMenu); document.addEventListener('click', this.onHideContextMenu);
} }
@@ -299,7 +300,7 @@ class SidePanel extends Component {
{this.state.tree_data && {this.state.tree_data &&
<TreeView <TreeView
permission={this.props.permission} permission={this.props.permission}
currentFileNode={this.props.currentFileNode} currentFilePath={this.props.currentFilePath}
treeData={this.state.tree_data} treeData={this.state.tree_data}
currentNode={this.state.currentNode} currentNode={this.state.currentNode}
isNodeItemFrezee={this.state.isNodeItemFrezee} isNodeItemFrezee={this.state.isNodeItemFrezee}

View File

@@ -114,7 +114,7 @@ class TreeNodeView extends React.Component {
treeView={this.props.treeView} treeView={this.props.treeView}
isNodeItemFrezee={this.props.isNodeItemFrezee} isNodeItemFrezee={this.props.isNodeItemFrezee}
permission={this.props.permission} permission={this.props.permission}
currentFileNode={this.props.currentFileNode} currentFilePath={this.props.currentFilePath}
/> />
); );
})} })}
@@ -173,7 +173,7 @@ class TreeNodeView extends React.Component {
let node = this.props.node; let node = this.props.node;
let { type, icon } = this.getNodeTypeAndIcon(); let { type, icon } = this.getNodeTypeAndIcon();
let hlClass = ""; let hlClass = "";
if (node.path === this.props.currentFileNode.path) { if (node.path === this.props.currentFilePath) {
hlClass = "tree-node-hight-light"; hlClass = "tree-node-hight-light";
} }
let customClass = "tree-node " + hlClass; let customClass = "tree-node " + hlClass;

View File

@@ -53,7 +53,7 @@ class TreeView extends React.PureComponent {
node={this.props.treeData.root} node={this.props.treeData.root}
isNodeItemFrezee={this.props.isNodeItemFrezee} isNodeItemFrezee={this.props.isNodeItemFrezee}
permission={this.props.permission} permission={this.props.permission}
currentFileNode={this.props.currentFileNode} currentFilePath={this.props.currentFilePath}
onShowContextMenu={this.props.onShowContextMenu} onShowContextMenu={this.props.onShowContextMenu}
/> />
</div> </div>

View File

@@ -74,14 +74,13 @@ class Wiki extends Component {
lastModified: '', lastModified: '',
permission: '', permission: '',
isFileLoading: false, isFileLoading: false,
currentFileNode: null,
searchedPath: null, searchedPath: null,
}; };
window.onpopstate = this.onpopstate; window.onpopstate = this.onpopstate;
} }
componentDidMount() { componentDidMount() {
this.loadFile({path: initialFilePath}); this.loadFile(initialFilePath);
} }
fileNameFromPath(filePath) { fileNameFromPath(filePath) {
@@ -116,14 +115,14 @@ class Wiki extends Component {
} }
onSearchedClick = (path) => { onSearchedClick = (path) => {
if (this.state.currentFileNode.path !== path) { if (this.state.currentFilePath !== path) {
this.setState({searchedPath : path}); this.setState({searchedPath : path});
} }
} }
onFileClick = (e, node) => { onFileClick = (e, node) => {
if (node.isMarkdown()) { if (node.isMarkdown()) {
this.loadFile(node); this.loadFile(node.path);
} else { } else {
const w=window.open('about:blank'); const w=window.open('about:blank');
const url = serviceUrl + '/lib/' + repoID + '/file' + node.path; const url = serviceUrl + '/lib/' + repoID + '/file' + node.path;
@@ -131,8 +130,7 @@ class Wiki extends Component {
} }
} }
loadFile(node) { loadFile(filePath) {
let filePath = node.path;
this.setState({isFileLoading: true}); this.setState({isFileLoading: true});
seafileAPI.getWikiFileContent(slug, filePath) seafileAPI.getWikiFileContent(slug, filePath)
.then(res => { .then(res => {
@@ -144,7 +142,6 @@ class Wiki extends Component {
fileName: this.fileNameFromPath(filePath), fileName: this.fileNameFromPath(filePath),
filePath: filePath, filePath: filePath,
isFileLoading: false, isFileLoading: false,
currentFileNode: node
}) })
}) })
@@ -180,7 +177,7 @@ class Wiki extends Component {
onCloseSide ={this.onCloseSide} onCloseSide ={this.onCloseSide}
editorUtilities={editorUtilities} editorUtilities={editorUtilities}
permission={this.state.permission} permission={this.state.permission}
currentFileNode={this.state.currentFileNode} currentFilePath={this.state.filePath}
searchedPath={this.state.searchedPath} searchedPath={this.state.searchedPath}
/> />
<MainPanel <MainPanel