diff --git a/frontend/src/pages/sdoc/sdoc-file-history/history-version.js b/frontend/src/pages/sdoc/sdoc-file-history/history-version.js index bfaafa360a..a25396f833 100644 --- a/frontend/src/pages/sdoc/sdoc-file-history/history-version.js +++ b/frontend/src/pages/sdoc/sdoc-file-history/history-version.js @@ -78,7 +78,9 @@ class HistoryVersion extends React.Component { event.stopPropagation(); event.nativeEvent.stopImmediatePropagation(); const { path } = this.props; - this.props.showDailyHistory(path); + this.props.showDailyHistory(path, () => { + this.props.onSelectHistoryVersion(path); + }); }; render() { diff --git a/frontend/src/pages/sdoc/sdoc-file-history/index.js b/frontend/src/pages/sdoc/sdoc-file-history/index.js index e3af64ac0a..4c6b35eb6d 100644 --- a/frontend/src/pages/sdoc/sdoc-file-history/index.js +++ b/frontend/src/pages/sdoc/sdoc-file-history/index.js @@ -48,14 +48,14 @@ class SdocFileHistory extends React.Component { }; } - onSelectHistoryVersion = (currentVersion, isShowChanges) => { + onSelectHistoryVersion = (currentVersion, lastVersion) => { this.setState({ isLoading: true, currentVersion }); seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => { return seafileAPI.getFileContent(res.data); }).then(res => { const currentVersionContent = res.data; - if (isShowChanges) { - seafileAPI.getLastFileRevision(historyRepoID, currentVersion.id, currentVersion.path).then(res => { + if (lastVersion) { + seafileAPI.getFileRevision(historyRepoID, lastVersion.commit_id, lastVersion.path).then(res => { return res.data ? seafileAPI.getFileContent(res.data) : { data: '' }; }).then(res => { const lastVersionContent = res.data; diff --git a/frontend/src/pages/sdoc/sdoc-file-history/side-panel.js b/frontend/src/pages/sdoc/sdoc-file-history/side-panel.js index 35990afe0c..b62cb6cf1e 100644 --- a/frontend/src/pages/sdoc/sdoc-file-history/side-panel.js +++ b/frontend/src/pages/sdoc/sdoc-file-history/side-panel.js @@ -146,8 +146,23 @@ class SidePanel extends Component { onSelectHistoryVersion = (path) => { const { isShowChanges } = this.props; const { historyGroups } = this.state; - const historyVersion = historyGroups[path[0]].children[path[1]].children[path[2]]; - this.props.onSelectHistoryVersion(historyVersion, isShowChanges); + const [monthIndex, dayIndex, dailyIndex] = path; + const monthHistoryGroup = historyGroups[monthIndex]; + const dayHistoryGroup = monthHistoryGroup.children[dayIndex]; + const currentVersion = dayHistoryGroup.children[dailyIndex]; + let lastVersion = ''; + if (isShowChanges) { + if (dayHistoryGroup.showDaily) { + lastVersion = dayHistoryGroup.children[dailyIndex + 1]; + } + if (!lastVersion) { + lastVersion = monthHistoryGroup.children[dayIndex + 1]?.children[0]; + } + if (!lastVersion) { + lastVersion = historyGroups[monthIndex + 1]?.children[0]?.children[0]; + } + } + this.props.onSelectHistoryVersion(currentVersion, lastVersion); }; copyHistoryFile = (historyVersion) => {