import React from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import { Button } from 'reactstrap'; /* eslint-disable */ import Prism from 'prismjs'; /* eslint-enable */ import { siteRoot, gettext } from './utils/constants'; import { seafileAPI } from './utils/seafile-api'; import axios from 'axios'; import DiffViewer from '@seafile/seafile-editor/dist/viewer/diff-viewer'; import { serialize } from '@seafile/seafile-editor/dist/utils/slate2markdown/serialize'; import Loading from './components/loading'; import toaster from './components/toast'; import ReviewComments from './components/review-list-view/review-comments'; import ReviewCommentDialog from './components/review-list-view/review-comment-dialog.js'; import { Tooltip } from 'reactstrap'; import AddReviewerDialog from './components/dialog/add-reviewer-dialog.js'; import { findRange } from '@seafile/slate-react'; import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap'; import classnames from 'classnames'; import HistoryList from './pages/review/history-list'; import { Value, Document, Block } from 'slate'; import './assets/css/fa-solid.css'; import './assets/css/fa-regular.css'; import './assets/css/fontawesome.css'; import './css/layout.css'; import './css/toolbar.css'; import './css/dirent-detail.css'; import './css/draft-review.css'; require('@seafile/seafile-editor/dist/editor/code-hight-package'); const { draftID, draftFileName, draftRepoID, draftFilePath, draftOriginFilePath, originFileExists } = window.draft.config; class Draft extends React.Component { constructor(props) { super(props); this.state = { draftContent: '', draftOriginContent: '', isLoading: true, isShowDiff: true, showDiffTip: false, activeTab: 'reviewInfo', commentsNumber: null, }; } componentDidMount() { this.initialContent(); } initialContent = () => { if (!originFileExists) { seafileAPI.getFileDownloadLink(draftRepoID, draftFilePath) .then(res => { seafileAPI.getFileContent(res.data) .then(res => { this.setState({ draftContent: res.data, draftOriginContent: res.data, isLoading: false, isShowDiff: false }); }); }); return; } axios.all([ seafileAPI.getFileDownloadLink(draftRepoID, draftFilePath), seafileAPI.getFileDownloadLink(draftRepoID, draftOriginFilePath) ]).then(axios.spread((res1, res2) => { axios.all([ seafileAPI.getFileContent(res1.data), seafileAPI.getFileContent(res2.data) ]).then(axios.spread((draftContent, draftOriginContent) => { this.setState({ draftContent: draftContent.data, draftOriginContent: draftOriginContent.data, isLoading: false }); })); })); } showDiffViewer = () => { return (
{this.state.isShowDiff ? : }
); } onSwitchShowDiff = () => { this.setState({ isShowDiff: !this.state.isShowDiff, }); } toggleDiffTip = () => { this.setState({ showDiffTip: !this.state.showDiffTip }); } showDiffButton = () => { return (
{gettext('View diff')}
); } onPublishDraft = () => { const OriginFileLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftOriginFilePath + '/'; seafileAPI.publishDraft(draftID).then(res => { window.location.href = OriginFileLink; }) } tabItemClick = (tab) => { if (this.state.activeTab !== tab) { this.setState({ activeTab: tab }); } } showNavItem = (showTab) => { switch(showTab) { case 'info': return ( { this.tabItemClick('reviewInfo');}} > ); case 'comments': return ( {this.tabItemClick('comments');}} > {this.state.commentsNumber > 0 &&
{this.state.commentsNumber}
}
); case 'history': return ( { this.tabItemClick('history');}} > ); } } renderNavItems = () => { return ( ); } render() { const draftLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftFilePath + '?mode=edit'; const OriginFileLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftOriginFilePath + '/'; return(
{this.state.isLoading ?
:
{this.showDiffViewer()}
}
{this.renderNavItems()} review info comments history list
); } } ReactDOM.render ( , document.getElementById('wrapper') );