mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 06:33:48 +00:00
fix: sdoc history diff toggle bug
This commit is contained in:
@@ -88,13 +88,11 @@ class SdocFileHistory extends React.Component {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelectHistoryVersion = (currentVersion, lastVersion) => {
|
updateLastVersionContent = (currentVersionContent, currentVersion, lastVersion) => {
|
||||||
this.setState({ isLoading: true, currentVersion });
|
if (!lastVersion) {
|
||||||
seafileAPI.getFileRevision(historyRepoID, currentVersion.commit_id, currentVersion.path).then(res => {
|
this.setContent(currentVersionContent, '');
|
||||||
return seafileAPI.getFileContent(res.data);
|
return;
|
||||||
}).then(res => {
|
}
|
||||||
const currentVersionContent = res.data;
|
|
||||||
if (lastVersion) {
|
|
||||||
if (lastVersion === 'init') {
|
if (lastVersion === 'init') {
|
||||||
const lastVersionContent = currentVersionContent ? this.getInitContent(currentVersionContent.children[0]) : this.getInitContentByPath(currentVersion.path);
|
const lastVersionContent = currentVersionContent ? this.getInitContent(currentVersionContent.children[0]) : this.getInitContentByPath(currentVersion.path);
|
||||||
const validCurrentVersionContent = currentVersionContent || this.getInitContentByPath(currentVersion.path);
|
const validCurrentVersionContent = currentVersionContent || this.getInitContentByPath(currentVersion.path);
|
||||||
@@ -113,9 +111,15 @@ class SdocFileHistory extends React.Component {
|
|||||||
toaster.danger(gettext(errorMessage));
|
toaster.danger(gettext(errorMessage));
|
||||||
this.setContent(currentVersionContent, '');
|
this.setContent(currentVersionContent, '');
|
||||||
});
|
});
|
||||||
} else {
|
};
|
||||||
this.setContent(currentVersionContent, '');
|
|
||||||
}
|
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;
|
||||||
|
this.updateLastVersionContent(currentVersionContent, currentVersion, lastVersion);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
const errorMessage = Utils.getErrorMsg(error, true);
|
const errorMessage = Utils.getErrorMsg(error, true);
|
||||||
toaster.danger(gettext(errorMessage));
|
toaster.danger(gettext(errorMessage));
|
||||||
@@ -127,21 +131,12 @@ class SdocFileHistory extends React.Component {
|
|||||||
this.setState({ currentVersionContent, lastVersionContent, isLoading: false, changes: [], currentDiffIndex: 0 });
|
this.setState({ currentVersionContent, lastVersionContent, isLoading: false, changes: [], currentDiffIndex: 0 });
|
||||||
};
|
};
|
||||||
|
|
||||||
onShowChanges = (isShowChanges) => {
|
onShowChanges = (isShowChanges, lastVersion) => {
|
||||||
if (isShowChanges) {
|
if (isShowChanges) {
|
||||||
const { currentVersionContent, currentVersion } = this.state;
|
const { currentVersionContent, currentVersion } = this.state;
|
||||||
this.setState({ isLoading: true, isShowChanges }, () => {
|
this.setState({ isLoading: true, isShowChanges }, () => {
|
||||||
localStorage.setItem('seahub-sdoc-history-show-changes', isShowChanges + '');
|
localStorage.setItem('seahub-sdoc-history-show-changes', isShowChanges + '');
|
||||||
seafileAPI.getNextFileRevision(historyRepoID, currentVersion.id, currentVersion.path).then(res => {
|
this.updateLastVersionContent(currentVersionContent, currentVersion, lastVersion);
|
||||||
return res.data ? seafileAPI.getFileContent(res.data) : { data: '' };
|
|
||||||
}).then(res => {
|
|
||||||
const lastVersionContent = res.data;
|
|
||||||
this.setContent(currentVersionContent, lastVersionContent);
|
|
||||||
}).catch(error => {
|
|
||||||
const errorMessage = Utils.getErrorMsg(error, true);
|
|
||||||
toaster.danger(gettext(errorMessage));
|
|
||||||
this.setContent(currentVersionContent, '');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -142,13 +142,11 @@ class SidePanel extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelectHistoryVersion = (path) => {
|
getLastVersion = (path, isShowChanges) => {
|
||||||
const { isShowChanges } = this.props;
|
|
||||||
const { historyGroups } = this.state;
|
const { historyGroups } = this.state;
|
||||||
const [monthIndex, dayIndex, dailyIndex] = path;
|
const [monthIndex, dayIndex, dailyIndex] = path;
|
||||||
const monthHistoryGroup = historyGroups[monthIndex];
|
const monthHistoryGroup = historyGroups[monthIndex];
|
||||||
const dayHistoryGroup = monthHistoryGroup.children[dayIndex];
|
const dayHistoryGroup = monthHistoryGroup.children[dayIndex];
|
||||||
const currentVersion = dayHistoryGroup.children[dailyIndex];
|
|
||||||
let lastVersion = '';
|
let lastVersion = '';
|
||||||
if (isShowChanges) {
|
if (isShowChanges) {
|
||||||
if (dayHistoryGroup.showDaily) {
|
if (dayHistoryGroup.showDaily) {
|
||||||
@@ -164,6 +162,17 @@ class SidePanel extends Component {
|
|||||||
lastVersion = 'init';
|
lastVersion = 'init';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return lastVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
onSelectHistoryVersion = (path) => {
|
||||||
|
const { historyGroups } = this.state;
|
||||||
|
const { isShowChanges } = this.props;
|
||||||
|
const [monthIndex, dayIndex, dailyIndex] = path;
|
||||||
|
const monthHistoryGroup = historyGroups[monthIndex];
|
||||||
|
const dayHistoryGroup = monthHistoryGroup.children[dayIndex];
|
||||||
|
const currentVersion = dayHistoryGroup.children[dailyIndex];
|
||||||
|
const lastVersion = this.getLastVersion(path, isShowChanges);
|
||||||
this.props.onSelectHistoryVersion(currentVersion, lastVersion);
|
this.props.onSelectHistoryVersion(currentVersion, lastVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -275,8 +284,22 @@ class SidePanel extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onShowChanges = () => {
|
onShowChanges = () => {
|
||||||
const { isShowChanges } = this.props;
|
const { isShowChanges, currentVersion } = this.props;
|
||||||
this.props.onShowChanges(!isShowChanges);
|
const { historyGroups } = this.state;
|
||||||
|
const nextShowChanges = !isShowChanges;
|
||||||
|
let lastVersion;
|
||||||
|
if (nextShowChanges) {
|
||||||
|
const { date } = currentVersion;
|
||||||
|
const momentDate = moment(date);
|
||||||
|
const month = momentDate.format('YYYY-MM');
|
||||||
|
const day = momentDate.format('YYYY-MM-DD');
|
||||||
|
const monthIndex = historyGroups.findIndex(item => item.month === month);
|
||||||
|
const dayIndex = historyGroups[monthIndex].children.findIndex(item => item.day === day);
|
||||||
|
const dailyIndex = historyGroups[monthIndex].children[dayIndex].children.findIndex(item => item.date === date);
|
||||||
|
const path = [monthIndex, dayIndex, dailyIndex];
|
||||||
|
lastVersion = this.getLastVersion(path, nextShowChanges);
|
||||||
|
}
|
||||||
|
this.props.onShowChanges(nextShowChanges, lastVersion);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
Reference in New Issue
Block a user