-
Notifications
You must be signed in to change notification settings - Fork 760
Expand file tree
/
Copy pathsettings-general-github.tsx
More file actions
117 lines (102 loc) · 3.13 KB
/
Copy pathsettings-general-github.tsx
File metadata and controls
117 lines (102 loc) · 3.13 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
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
import * as React from 'react';
import {
Button,
ButtonGroup,
Callout,
Checkbox,
FormGroup,
} from '@blueprintjs/core';
import { observer } from 'mobx-react';
import { AppState } from '../state';
interface GitHubSettingsProps {
appState: AppState;
}
/**
* Settings content to manage GitHub-related preferences.
*/
export const GitHubSettings = observer(
class GitHubSettings extends React.Component<GitHubSettingsProps> {
constructor(props: GitHubSettingsProps) {
super(props);
this.signIn = this.signIn.bind(this);
this.handlePublishGistAsRevisionChange =
this.handlePublishGistAsRevisionChange.bind(this);
}
private static publishGistAsRevisionInstructions = `
Enable this option to always publish your fiddle as a revision of the
default fiddle gist values.`.trim();
/**
* Render the "logged out" settings experience.
*/
public renderNotSignedIn(): JSX.Element {
return (
<Callout>
<p>
Your fiddles can be published as GitHub Gists - that way you can
share your fiddles with the world!
</p>
<Button onClick={this.signIn} icon="log-in" text="Sign in" />
</Callout>
);
}
/**
* Render the "logged in" settings experience.
*/
public renderSignedIn(): JSX.Element {
const { gitHubLogin } = this.props.appState;
const signOut = this.props.appState.signOutGitHub;
return (
<Callout>
<p>
Your fiddles can be published as public GitHub Gists. Using the
personal access token you gave us, we logged you into GitHub as{' '}
<code>{gitHubLogin}</code>.
</p>
<ButtonGroup>
<Button onClick={this.signIn} icon="log-in" text="Update token" />
<Button onClick={signOut} icon="log-out" text="Sign out" />
</ButtonGroup>
</Callout>
);
}
/**
* Handles a change on whether or not the gist should be published
* as a revision on top of the default fiddle gist.
*/
public handlePublishGistAsRevisionChange(
event: React.FormEvent<HTMLInputElement>,
) {
const { checked } = event.currentTarget;
this.props.appState.isPublishingGistAsRevision = checked;
}
public render() {
const { gitHubToken } = this.props.appState;
const { isPublishingGistAsRevision } = this.props.appState;
const maybeSignedIn = !!gitHubToken
? this.renderSignedIn()
: this.renderNotSignedIn();
return (
<div>
<h4>GitHub</h4>
{maybeSignedIn}
<Callout>
<FormGroup>
<p>{GitHubSettings.publishGistAsRevisionInstructions}</p>
<Checkbox
checked={isPublishingGistAsRevision}
label="Publish as revision."
onChange={this.handlePublishGistAsRevisionChange}
/>
</FormGroup>
</Callout>
</div>
);
}
/**
* Simply shows the GitHub Token dialog.
*/
private signIn() {
this.props.appState.isTokenDialogShowing = true;
}
},
);