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 402
/
Copy pathcreate-dialog-container.js
123 lines (105 loc) · 2.93 KB
/
create-dialog-container.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React from 'react';
import PropTypes from 'prop-types';
import {QueryRenderer, graphql} from 'react-relay';
import CreateDialogController from '../controllers/create-dialog-controller';
import ObserveModel from '../views/observe-model';
import {PAGE_SIZE} from '../views/repository-home-selection-view';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
import {getEndpoint} from '../models/endpoint';
import {GithubLoginModelPropType} from '../prop-types';
const DOTCOM = getEndpoint('github.com');
export default class CreateDialogContainer extends React.Component {
static propTypes = {
// Model
loginModel: GithubLoginModelPropType.isRequired,
request: PropTypes.object.isRequired,
error: PropTypes.instanceOf(Error),
inProgress: PropTypes.bool.isRequired,
// Atom environment
currentWindow: PropTypes.object.isRequired,
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
}
constructor(props) {
super(props);
this.lastProps = null;
}
render() {
return (
<ObserveModel model={this.props.loginModel} fetchData={this.fetchToken}>
{this.renderWithToken}
</ObserveModel>
);
}
renderWithToken = token => {
if (!token) {
return null;
}
const environment = RelayNetworkLayerManager.getEnvironmentForHost(DOTCOM, token);
const query = graphql`
query createDialogContainerQuery(
$organizationCount: Int!
$organizationCursor: String
) {
viewer {
...createDialogController_user @arguments(
organizationCount: $organizationCount
organizationCursor: $organizationCursor
)
}
}
`;
const variables = {
organizationCount: PAGE_SIZE,
organizationCursor: null,
// Force QueryRenderer to re-render when dialog request state changes
error: this.props.error,
inProgress: this.props.inProgress,
};
return (
<QueryRenderer
environment={environment}
query={query}
variables={variables}
render={this.renderWithResult}
/>
);
}
renderWithResult = ({error, props}) => {
if (error) {
return this.renderError(error);
}
if (!props && !this.lastProps) {
return this.renderLoading();
}
const currentProps = props || this.lastProps;
return (
<CreateDialogController
user={currentProps.viewer}
isLoading={false}
{...this.props}
/>
);
}
renderError(error) {
return (
<CreateDialogController
user={null}
error={error}
isLoading={false}
{...this.props}
/>
);
}
renderLoading() {
return (
<CreateDialogController
user={null}
isLoading={true}
{...this.props}
/>
);
}
fetchToken = loginModel => loginModel.getToken(DOTCOM.getLoginAccount())
}