1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

improve code (#4370)

* improve code

* optimized code
This commit is contained in:
杨顺强
2019-12-19 13:44:30 +08:00
committed by Daniel Pan
parent 9c10cbf9f7
commit 4e584c8f65
7 changed files with 18 additions and 38 deletions

View File

@@ -9,7 +9,6 @@ import { Utils } from '../../utils/utils';
import UploadLink from '../../models/upload-link'; import UploadLink from '../../models/upload-link';
import toaster from '../toast'; import toaster from '../toast';
import SendLink from '../send-link'; import SendLink from '../send-link';
import SessionExpiredTip from '../session-expired-tip';
const propTypes = { const propTypes = {
itemPath: PropTypes.string.isRequired, itemPath: PropTypes.string.isRequired,
@@ -45,13 +44,11 @@ class GenerateUploadLink extends React.Component {
this.setState({sharedUploadInfo: sharedUploadInfo}); this.setState({sharedUploadInfo: sharedUploadInfo});
} }
}).catch((err) => { }).catch((err) => {
if (err.response.status === 403) { let errMsg = Utils.getErrorMsg(err, true);
toaster.danger( if (!err.response || err.response.status !== 403) {
<SessionExpiredTip />, toaster.danger(errMsg);
{id: 'session_expired', duration: 3600}
);
this.props.closeShareDialog();
} }
this.props.closeShareDialog();
}); });
} }

View File

@@ -2,10 +2,12 @@ import React from 'react';
import { gettext, loginUrl } from '../utils/constants'; import { gettext, loginUrl } from '../utils/constants';
function PermissionDeniedTip() { function PermissionDeniedTip() {
let reloginUrl = `${loginUrl}?next=${encodeURIComponent(location.href)}`;
let errorTip = gettext('Permission denied. Plaese try {placeholder-left}login again.{placeholder-right}');
errorTip = errorTip.replace('{placeholder-left}', '<a class="action-link p-0" href='+ reloginUrl + '>')
errorTip = errorTip.replace('{placeholder-right}', '</a>');
return( return(
<span className="error">{gettext('Permission denied. Please try')}{' '} <span className="error" dangerouslySetInnerHTML={{__html: errorTip}}></span>
<a className="action-link p-0" href={`${loginUrl}?next=${encodeURIComponent(location.href)}`}>{gettext('login again.')}</a>
</span>
); );
} }

View File

@@ -1,12 +0,0 @@
import React from 'react';
import { gettext, loginUrl } from '../utils/constants';
function SessionExpiredTip() {
return(
<span className="error">{gettext('You are logged out.')}{' '}
<a className="action-link p-0" href={`${loginUrl}?next=${encodeURIComponent(location.href)}`}>{gettext('Login again.')}</a>
</span>
);
}
export default SessionExpiredTip;

View File

@@ -96,7 +96,7 @@ class GroupView extends React.Component {
}).catch((error) => { }).catch((error) => {
this.setState({ this.setState({
isLoading: false, isLoading: false,
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 errMessage: Utils.getErrorMsg(error, true) // true: show login tip if 403
}); });
}); });
} }
@@ -115,7 +115,7 @@ class GroupView extends React.Component {
}).catch((error) => { }).catch((error) => {
this.setState({ this.setState({
isLoading: false, isLoading: false,
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403 errMessage: Utils.getErrorMsg(error, true) // true: show login tip if 403
}); });
}); });
} }
@@ -507,7 +507,7 @@ class GroupView extends React.Component {
</div> </div>
<div className="cur-view-content"> <div className="cur-view-content">
{this.state.isLoading && <Loading />} {this.state.isLoading && <Loading />}
{(!this.state.isLoading && errMessage) && errMessage} {(!this.state.isLoading && errMessage) && <div className="error text-center mt-2">{errMessage}</div>}
{(!this.state.isLoading && this.state.repoList.length === 0) && emptyTip} {(!this.state.isLoading && this.state.repoList.length === 0) && emptyTip}
{(!this.state.isLoading && this.state.repoList.length > 0) && {(!this.state.isLoading && this.state.repoList.length > 0) &&
<SharedRepoListView <SharedRepoListView

View File

@@ -205,7 +205,7 @@ class GroupsView extends React.Component {
</div> </div>
<div className="cur-view-content cur-view-content-groups"> <div className="cur-view-content cur-view-content-groups">
{this.state.isLoading && <Loading />} {this.state.isLoading && <Loading />}
{(!this.state.isLoading && this.state.errorMsg) && this.state.errorMsg} {(!this.state.isLoading && this.state.errorMsg) && <div className="error text-center mt-2">{this.state.errorMsg}</div>}
{(!this.state.isLoading && !this.state.errorMsg && this.state.groupList.length == 0) && emptyTip} {(!this.state.isLoading && !this.state.errorMsg && this.state.groupList.length == 0) && emptyTip}
{!this.state.isLoading && this.state.groupList.map((group, index) => { {!this.state.isLoading && this.state.groupList.map((group, index) => {
return ( return (

View File

@@ -18,7 +18,6 @@ import LibDecryptDialog from '../../components/dialog/lib-decrypt-dialog';
import LibContentToolbar from './lib-content-toolbar'; import LibContentToolbar from './lib-content-toolbar';
import LibContentContainer from './lib-content-container'; import LibContentContainer from './lib-content-container';
import FileUploader from '../../components/file-uploader/file-uploader'; import FileUploader from '../../components/file-uploader/file-uploader';
import SessionExpiredTip from '../../components/session-expired-tip';
const propTypes = { const propTypes = {
pathPrefix: PropTypes.array.isRequired, pathPrefix: PropTypes.array.isRequired,
@@ -449,11 +448,9 @@ class LibContentView extends React.Component {
}); });
}); });
}).catch((err) => { }).catch((err) => {
if (err.response.status === 403) { let errMsg = Utils.getErrorMsg(err, true);
toaster.danger( if (!err.response || err.response.status !== 403) {
<SessionExpiredTip />, toaster.danger(errMsg);
{id: 'session_expired', duration: 3600}
);
} }
this.setState({ this.setState({
isFileLoading: false, isFileLoading: false,
@@ -496,11 +493,8 @@ class LibContentView extends React.Component {
this.getThumbnails(repoID, path, this.state.direntList); this.getThumbnails(repoID, path, this.state.direntList);
} }
}).catch((err) => { }).catch((err) => {
if (err.response.status === 403) { Utils.getErrorMsg(err, true);
toaster.danger( if (err.response && err.response.status === 403) {
<SessionExpiredTip />,
{id: 'session_expired', duration: 3600}
);
this.setState({isDirentListLoading: false}); this.setState({isDirentListLoading: false});
return; return;
} }

View File

@@ -981,7 +981,6 @@ export const Utils = {
<PermissionDeniedTip />, <PermissionDeniedTip />,
{id: 'permission_denied', duration: 3600} {id: 'permission_denied', duration: 3600}
); );
return;
} }
errorMsg = gettext('Permission denied'); errorMsg = gettext('Permission denied');
} else if (error.response.data && } else if (error.response.data &&