mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
repair router bug
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Router, Link } from '@reach/router';
|
import { Router } from '@reach/router';
|
||||||
import { gettext, siteRoot } from './utils/constants';
|
import { siteRoot } from './utils/constants';
|
||||||
import SidePanel from './components/side-panel';
|
import SidePanel from './components/side-panel';
|
||||||
import MainPanel from './components/main-panel';
|
import MainPanel from './components/main-panel';
|
||||||
import DraftsView from './pages/drafts/drafts-view';
|
import DraftsView from './pages/drafts/drafts-view';
|
||||||
@@ -53,8 +53,9 @@ class App extends Component {
|
|||||||
draftList:[],
|
draftList:[],
|
||||||
isLoadingDraft: true,
|
isLoadingDraft: true,
|
||||||
currentTab: '/',
|
currentTab: '/',
|
||||||
pathPrefix: null,
|
pathPrefix: [],
|
||||||
};
|
};
|
||||||
|
this.dirViewPanels = ['my-libs', 'shared-libs', 'org']; // and group
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -100,41 +101,55 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tabItemClick = (tabName, groupID) => {
|
tabItemClick = (tabName, groupID) => {
|
||||||
let pathPrefix = this.generatorPrefix(tabName, groupID);
|
let pathPrefix = [];
|
||||||
|
if (groupID || this.dirViewPanels.indexOf(tabName) > -1) {
|
||||||
|
pathPrefix = this.generatorPrefix(tabName, groupID);
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
currentTab: tabName,
|
currentTab: tabName,
|
||||||
pathPrefix: pathPrefix
|
pathPrefix: pathPrefix
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generatorPrefix = (currentTab, groupID) => {
|
generatorPrefix = (tabName, groupID) => {
|
||||||
if (groupID) { //group
|
let pathPrefix = [];
|
||||||
return (
|
if (groupID) {
|
||||||
<Fragment>
|
let navTab1 = {
|
||||||
<Link to={siteRoot + 'groups/'} className="normal">{gettext('Groups')}</Link>
|
url: siteRoot + 'groups/',
|
||||||
<span className="path-split">/</span>
|
showName: 'Groups',
|
||||||
<Link to={siteRoot + 'group/' + groupID + '/'} className="normal">{currentTab}</Link>
|
name: 'groups',
|
||||||
<span className="path-split">/</span>
|
id: null,
|
||||||
</Fragment>
|
}
|
||||||
);
|
let navTab2 = {
|
||||||
|
url: siteRoot + 'group/' + groupID + '/',
|
||||||
|
showName: tabName,
|
||||||
|
name: tabName,
|
||||||
|
id: groupID,
|
||||||
|
};
|
||||||
|
pathPrefix.push(navTab1);
|
||||||
|
pathPrefix.push(navTab2);
|
||||||
|
} else {
|
||||||
|
let navTab = {
|
||||||
|
url: siteRoot + tabName + '/',
|
||||||
|
showName: this.getTabShowName(tabName, groupID),
|
||||||
|
name: tabName,
|
||||||
|
id: null,
|
||||||
|
};
|
||||||
|
pathPrefix.push(navTab);
|
||||||
}
|
}
|
||||||
if (currentTab === 'my-libs') {
|
return pathPrefix;
|
||||||
return (
|
}
|
||||||
<Fragment>
|
|
||||||
<Link to={siteRoot + 'my-libs/'} className="normal">{gettext('Libraries')}</Link>
|
getTabShowName = (tabName) => {
|
||||||
<span className="path-split">/</span>
|
if (tabName === 'my-libs') {
|
||||||
</Fragment>
|
return 'Libraries';
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (currentTab === 'shared-libs') {
|
if (tabName === 'shared-libs') {
|
||||||
return (
|
return 'Shared with me';
|
||||||
<Fragment>
|
}
|
||||||
<Link to={siteRoot + 'shared-libs/'} className="normal">{gettext('Shared with me')}</Link>
|
if (tabName === 'org') {
|
||||||
<span className="path-split">/</span>
|
return 'Shared with all';
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -170,9 +185,9 @@ class App extends Component {
|
|||||||
<SharedLibrariesWrapper path={siteRoot + 'shared-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
<SharedLibrariesWrapper path={siteRoot + 'shared-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
||||||
<MyLibraries path={siteRoot + 'my-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
<MyLibraries path={siteRoot + 'my-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
||||||
<MyLibDeleted path={siteRoot + 'my-libs/deleted/'} onSearchedClick={this.onSearchedClick} />
|
<MyLibDeleted path={siteRoot + 'my-libs/deleted/'} onSearchedClick={this.onSearchedClick} />
|
||||||
<DirView path={siteRoot + 'library/:repoID/*'} pathPrefix={this.state.pathPrefix} onMenuClick={this.onShowSidePanel}/>
|
<DirView path={siteRoot + 'library/:repoID/*'} pathPrefix={this.state.pathPrefix} onMenuClick={this.onShowSidePanel} onTabNavClick={this.tabItemClick}/>
|
||||||
<Groups path={siteRoot + 'groups'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
<Groups path={siteRoot + 'groups'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
||||||
<Group path={siteRoot + 'group/:groupID'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
<Group path={siteRoot + 'group/:groupID'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} onTabNavClick={this.tabItemClick}/>
|
||||||
<WikisWrapper path={siteRoot + 'wikis'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
<WikisWrapper path={siteRoot + 'wikis'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
||||||
</Router>
|
</Router>
|
||||||
</MainPanel>
|
</MainPanel>
|
||||||
|
@@ -5,9 +5,10 @@ import { siteRoot, gettext } from '../../utils/constants';
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoName: PropTypes.string.isRequired,
|
repoName: PropTypes.string.isRequired,
|
||||||
pathPrefix: PropTypes.object,
|
|
||||||
currentPath: PropTypes.string.isRequired,
|
currentPath: PropTypes.string.isRequired,
|
||||||
onPathClick: PropTypes.func.isRequired,
|
onPathClick: PropTypes.func.isRequired,
|
||||||
|
onTabNavClick: PropTypes.func,
|
||||||
|
pathPrefix: PropTypes.array,
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirPath extends React.Component {
|
class DirPath extends React.Component {
|
||||||
@@ -17,6 +18,10 @@ class DirPath extends React.Component {
|
|||||||
this.props.onPathClick(path);
|
this.props.onPathClick(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTabNavClick = (tabName, id) => {
|
||||||
|
this.props.onTabNavClick(tabName, id);
|
||||||
|
}
|
||||||
|
|
||||||
turnPathToLink = (path) => {
|
turnPathToLink = (path) => {
|
||||||
path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path;
|
path = path[path.length - 1] === '/' ? path.slice(0, path.length - 1) : path;
|
||||||
let pathList = path.split('/');
|
let pathList = path.split('/');
|
||||||
@@ -47,13 +52,27 @@ class DirPath extends React.Component {
|
|||||||
let pathElem = this.turnPathToLink(currentPath);
|
let pathElem = this.turnPathToLink(currentPath);
|
||||||
return (
|
return (
|
||||||
<div className="path-containter">
|
<div className="path-containter">
|
||||||
{this.props.pathPrefix ?
|
{this.props.pathPrefix && this.props.pathPrefix.map((item, index) => {
|
||||||
this.props.pathPrefix :
|
return (
|
||||||
<Fragment>
|
<Fragment key={index}>
|
||||||
<Link to={siteRoot + 'my-libs/'} className="normal">{gettext('Libraries')}</Link>
|
<Link to={item.url} className="normal" onClick={() => this.onTabNavClick(item.name, item.id)}>{gettext(item.showName)}</Link>
|
||||||
<span className="path-split">/</span>
|
<span className="path-split">/</span>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{this.props.pathPrefix && this.props.pathPrefix.length === 0 && (
|
||||||
|
<Fragment>
|
||||||
|
<Link to={siteRoot + 'my-libs/'} className="normal" onClick={() => this.onTabNavClick.bind(this, 'my-libs')}>{gettext('Libraries')}</Link>
|
||||||
|
<span className="path-split">/</span>
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
{!this.props.pathPrefix && (
|
||||||
|
<Fragment>
|
||||||
|
<a href={siteRoot + 'my-libs/'} className="normal" onClick={() => this.onTabNavClick.bind(this, 'my-libs')}>{gettext('Libraries')}</a>
|
||||||
|
<span className="path-split">/</span>
|
||||||
|
</Fragment>
|
||||||
|
)}
|
||||||
{currentPath === '/' ?
|
{currentPath === '/' ?
|
||||||
<span>{repoName}</span>:
|
<span>{repoName}</span>:
|
||||||
<a className="path-link" data-path="/" onClick={this.onPathClick}>{repoName}</a>
|
<a className="path-link" data-path="/" onClick={this.onPathClick}>{repoName}</a>
|
||||||
|
@@ -5,11 +5,12 @@ import DirTool from './dir-tool';
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
pathPrefix: PropTypes.object.isRequired,
|
|
||||||
repoName: PropTypes.string.isRequired,
|
repoName: PropTypes.string.isRequired,
|
||||||
permission: PropTypes.bool.isRequired,
|
permission: PropTypes.bool.isRequired,
|
||||||
currentPath: PropTypes.string.isRequired,
|
currentPath: PropTypes.string.isRequired,
|
||||||
onPathClick: PropTypes.func.isRequired,
|
onPathClick: PropTypes.func.isRequired,
|
||||||
|
onTabNavClick: PropTypes.func,
|
||||||
|
pathPrefix: PropTypes.array,
|
||||||
};
|
};
|
||||||
|
|
||||||
class CurDirPath extends React.Component {
|
class CurDirPath extends React.Component {
|
||||||
@@ -22,6 +23,7 @@ class CurDirPath extends React.Component {
|
|||||||
pathPrefix={this.props.pathPrefix}
|
pathPrefix={this.props.pathPrefix}
|
||||||
currentPath={this.props.currentPath}
|
currentPath={this.props.currentPath}
|
||||||
onPathClick={this.props.onPathClick}
|
onPathClick={this.props.onPathClick}
|
||||||
|
onTabNavClick={this.props.onTabNavClick}
|
||||||
/>
|
/>
|
||||||
<DirTool
|
<DirTool
|
||||||
repoID={this.props.repoID}
|
repoID={this.props.repoID}
|
||||||
|
@@ -14,7 +14,7 @@ import FileUploader from '../file-uploader/file-uploader';
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
currentRepo: PropTypes.object,
|
currentRepo: PropTypes.object,
|
||||||
pathPrefix: PropTypes.object.isRequired,
|
pathPrefix: PropTypes.array.isRequired,
|
||||||
path: PropTypes.string.isRequired,
|
path: PropTypes.string.isRequired,
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
repoName: PropTypes.string.isRequired,
|
repoName: PropTypes.string.isRequired,
|
||||||
@@ -40,6 +40,7 @@ const propTypes = {
|
|||||||
onFileTagChanged: PropTypes.func.isRequired,
|
onFileTagChanged: PropTypes.func.isRequired,
|
||||||
onMenuClick: PropTypes.func.isRequired,
|
onMenuClick: PropTypes.func.isRequired,
|
||||||
onPathClick: PropTypes.func.isRequired,
|
onPathClick: PropTypes.func.isRequired,
|
||||||
|
onTabNavClick: PropTypes.func.isRequired,
|
||||||
updateDirent: PropTypes.func.isRequired,
|
updateDirent: PropTypes.func.isRequired,
|
||||||
onSearchedClick: PropTypes.func.isRequired,
|
onSearchedClick: PropTypes.func.isRequired,
|
||||||
onFileUploadSuccess: PropTypes.func.isRequired,
|
onFileUploadSuccess: PropTypes.func.isRequired,
|
||||||
@@ -152,6 +153,7 @@ class DirPanel extends React.Component {
|
|||||||
currentPath={this.props.path}
|
currentPath={this.props.path}
|
||||||
permission={this.props.permission}
|
permission={this.props.permission}
|
||||||
onPathClick={this.props.onPathClick}
|
onPathClick={this.props.onPathClick}
|
||||||
|
onTabNavClick={this.props.onTabNavClick}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="cur-view-content">
|
<div className="cur-view-content">
|
||||||
|
@@ -11,7 +11,8 @@ import FileTag from '../../models/file-tag';
|
|||||||
import Repo from '../../models/repo';
|
import Repo from '../../models/repo';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
pathPrefix: PropTypes.object.isRequired,
|
pathPrefix: PropTypes.array.isRequired,
|
||||||
|
onTabNavClick: PropTypes.func.isRequired,
|
||||||
onMenuClick: PropTypes.func.isRequired,
|
onMenuClick: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -456,6 +457,7 @@ class DirView extends React.Component {
|
|||||||
onFileTagChanged={this.onFileTagChanged}
|
onFileTagChanged={this.onFileTagChanged}
|
||||||
onMenuClick={this.onMenuClick}
|
onMenuClick={this.onMenuClick}
|
||||||
onPathClick={this.onPathClick}
|
onPathClick={this.onPathClick}
|
||||||
|
onTabNavClick={this.props.onTabNavClick}
|
||||||
updateDirent={this.updateDirent}
|
updateDirent={this.updateDirent}
|
||||||
switchViewMode={this.switchViewMode}
|
switchViewMode={this.switchViewMode}
|
||||||
onSearchedClick={this.onSearchedClick}
|
onSearchedClick={this.onSearchedClick}
|
||||||
|
@@ -180,6 +180,10 @@ class GroupView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTabNavClick = (tabName) => {
|
||||||
|
this.props.onTabNavClick(tabName);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { errMessage, emptyTip, currentGroup } = this.state;
|
let { errMessage, emptyTip, currentGroup } = this.state;
|
||||||
let isShowSettingIcon = !(currentGroup && currentGroup.parent_group_id !== 0 && currentGroup.admins.indexOf(username) === -1);
|
let isShowSettingIcon = !(currentGroup && currentGroup.parent_group_id !== 0 && currentGroup.admins.indexOf(username) === -1);
|
||||||
@@ -203,7 +207,7 @@ class GroupView extends React.Component {
|
|||||||
{currentGroup && (
|
{currentGroup && (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="path-container">
|
<div className="path-container">
|
||||||
<Link to={`${siteRoot}groups/`}>{gettext("Groups")}</Link>
|
<Link to={`${siteRoot}groups/`} onClick={() => this.onTabNavClick('groups')}>{gettext("Groups")}</Link>
|
||||||
<span className="path-split">/</span>
|
<span className="path-split">/</span>
|
||||||
<span>{currentGroup.name}</span>
|
<span>{currentGroup.name}</span>
|
||||||
{currentGroup.parent_group_id !== 0 && (
|
{currentGroup.parent_group_id !== 0 && (
|
||||||
|
Reference in New Issue
Block a user