import React from 'react';
import ReactDom from 'react-dom';
import PropTypes from 'prop-types';
import { navigate } from '@gatsbyjs/reach-router';
import { Utils } from './utils/utils';
import { gettext, 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, canRestoreRepo,
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, { replace: 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) => {
this.setState({
isLoading: false,
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403
});
});
};
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} | ; })}
---|