import React from 'react';
import ReactDOM from 'react-dom';
import { navigate } from '@reach/router';
import moment from 'moment';
import { Utils } from './utils/utils';
import { gettext, loginUrl, siteRoot, mediaUrl, logoPath, logoWidth, logoHeight, siteTitle } from './utils/constants';
import { seafileAPI } from './utils/seafile-api';
import Loading from './components/loading';
import ModalPortal from './components/modal-portal';
import toaster from './components/toast';
import CommonToolbar from './components/toolbar/common-toolbar';
import ConfirmRestoreRepo from './components/dialog/confirm-restore-repo';
import './css/toolbar.css';
import './css/search.css';
import './css/repo-snapshot.css';
const {
repoID, repoName, isRepoOwner,
commitID, commitTime, commitDesc, commitRelativeTime,
showAuthor, authorAvatarURL, authorName, authorNickName
} = window.app.pageOptions;
class RepoSnapshot extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
errorMsg: '',
folderPath: '/',
folderItems: [],
isConfirmDialogOpen: false
};
}
componentDidMount() {
this.renderFolder(this.state.folderPath);
}
toggleDialog = () => {
this.setState({
isConfirmDialogOpen: !this.state.isConfirmDialogOpen
});
}
onSearchedClick = (selectedItem) => {
if (selectedItem.is_dir === true) {
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
navigate(url, {repalce: true});
} else {
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path);
let newWindow = window.open('about:blank');
newWindow.location.href = url;
}
}
goBack = (e) => {
e.preventDefault();
window.history.back();
}
renderFolder = (folderPath) => {
this.setState({
folderPath: folderPath,
folderItems: [],
isLoading: true
});
seafileAPI.listCommitDir(repoID, commitID, folderPath).then((res) => {
this.setState({
isLoading: false,
folderItems: res.data.dirent_list
});
}).catch((error) => {
if (error.response) {
if (error.response.status == 403) {
this.setState({
isLoading: false,
errorMsg: gettext('Permission denied')
});
location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`;
} else {
this.setState({
isLoading: false,
errorMsg: gettext('Error')
});
}
} else {
this.setState({
isLoading: false,
errorMsg: gettext('Please check the network.')
});
}
});
}
clickFolderPath = (folderPath, e) => {
e.preventDefault();
this.renderFolder(folderPath);
}
renderPath = () => {
const path = this.state.folderPath;
const pathList = path.split('/');
if (path == '/') {
return repoName;
}
return (
{commitDesc} {gettext('Current path: ')}{this.renderPath()}(${commitTime})`}}>
{folderPath == '/' && (
{authorNickName}
{errorMsg}
; } return ({item.text} | ; })}
---|