This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 409
Expand file tree
/
Copy pathcommit-detail-container.js
More file actions
70 lines (60 loc) · 1.88 KB
/
commit-detail-container.js
File metadata and controls
70 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {CompositeDisposable} from 'event-kit';
import ObserveModel from '../views/observe-model';
import LoadingView from '../views/loading-view';
import CommitDetailController from '../controllers/commit-detail-controller';
export default class CommitDetailContainer extends React.Component {
static propTypes = {
repository: PropTypes.object.isRequired,
sha: PropTypes.string.isRequired,
itemType: PropTypes.func.isRequired,
}
constructor(props) {
super(props);
this.lastCommit = null;
this.sub = new CompositeDisposable();
}
fetchData = repository => {
return yubikiri({
commit: repository.getCommit(this.props.sha),
currentBranch: repository.getCurrentBranch(),
currentRemote: async query => repository.getRemoteForBranch((await query.currentBranch).getName()),
isCommitPushed: repository.isCommitPushed(this.props.sha),
});
}
render() {
return (
<ObserveModel model={this.props.repository} fetchData={this.fetchData}>
{this.renderResult}
</ObserveModel>
);
}
renderResult = data => {
const currentCommit = data && data.commit;
if (currentCommit !== this.lastCommit) {
this.sub.dispose();
if (currentCommit && currentCommit.isPresent()) {
this.sub = new CompositeDisposable(
...currentCommit.getMultiFileDiff().getFilePatches().map(fp => fp.onDidChangeRenderStatus(() => {
this.forceUpdate();
})),
);
}
this.lastCommit = currentCommit;
}
if (this.props.repository.isLoading() || data === null || !data.commit.isPresent()) {
return <LoadingView />;
}
return (
<CommitDetailController
{...data}
{...this.props}
/>
);
}
componentWillUnmount() {
this.sub.dispose();
}
}