@@ -18,11 +18,11 @@ import context from 'browser/lib/context'
18
18
import ConfigManager from 'browser/main/lib/ConfigManager'
19
19
import _ from 'lodash'
20
20
import { findNoteTitle } from 'browser/lib/findNoteTitle'
21
- import convertModeName from 'browser/lib/convertModeName'
22
21
import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig'
23
22
import FullscreenButton from './FullscreenButton'
24
23
import TrashButton from './TrashButton'
25
24
import RestoreButton from './RestoreButton'
25
+ import GistButton from './GistButton'
26
26
import PermanentDeleteButton from './PermanentDeleteButton'
27
27
import InfoButton from './InfoButton'
28
28
import InfoPanel from './InfoPanel'
@@ -31,6 +31,7 @@ import { formatDate } from 'browser/lib/date-formatter'
31
31
import i18n from 'browser/lib/i18n'
32
32
import { confirmDeleteNote } from 'browser/lib/confirmDeleteNote'
33
33
import markdownToc from 'browser/lib/markdown-toc-generator'
34
+ import { getGithubApi , CREATE_SINGLE_GIST , EDIT_SINGLE_GIST , mapToGist } from 'browser/main/lib/dataApi/github-api.js'
34
35
35
36
const electron = require ( 'electron' )
36
37
const { remote } = electron
@@ -74,6 +75,7 @@ class SnippetNoteDetail extends React.Component {
74
75
componentWillReceiveProps ( nextProps ) {
75
76
if ( nextProps . note . key !== this . props . note . key && ! this . state . isMovingNote ) {
76
77
if ( this . saveQueue != null ) this . saveNow ( )
78
+ if ( this . saveGithubQueue != null ) this . saveGithub ( )
77
79
const nextNote = Object . assign ( {
78
80
description : ''
79
81
} , nextProps . note , {
@@ -96,6 +98,7 @@ class SnippetNoteDetail extends React.Component {
96
98
97
99
componentWillUnmount ( ) {
98
100
if ( this . saveQueue != null ) this . saveNow ( )
101
+ if ( this . saveGithubQueue != null ) this . saveGithub ( )
99
102
ee . off ( 'code:generate-toc' , this . generateToc )
100
103
}
101
104
@@ -128,6 +131,11 @@ class SnippetNoteDetail extends React.Component {
128
131
this . saveQueue = setTimeout ( ( ) => {
129
132
this . saveNow ( )
130
133
} , 1000 )
134
+ clearTimeout ( this . saveGithubQueue )
135
+ this . saveGithubQueue = setTimeout ( ( ) => {
136
+ this . saveGithub ( )
137
+ } , 5 * 60 * 1000
138
+ )
131
139
}
132
140
133
141
saveNow ( ) {
@@ -146,6 +154,13 @@ class SnippetNoteDetail extends React.Component {
146
154
} )
147
155
}
148
156
157
+ saveGithub ( ) {
158
+ const { note } = this . props
159
+ clearTimeout ( this . saveGithubQueue )
160
+ this . saveGithubQueue = null
161
+ getGithubApi ( EDIT_SINGLE_GIST ) ( mapToGist ( note ) )
162
+ }
163
+
149
164
handleFolderChange ( e ) {
150
165
const { note } = this . state
151
166
const value = this . refs . folder . value
@@ -198,11 +213,10 @@ class SnippetNoteDetail extends React.Component {
198
213
199
214
handleTrashButtonClick ( e ) {
200
215
const { note } = this . state
201
- const { isTrashed } = note
216
+ const { isTrashed, gistId } = note
202
217
const { confirmDeletion } = this . props . config . ui
203
-
204
- if ( isTrashed ) {
205
- if ( confirmDeleteNote ( confirmDeletion , true ) ) {
218
+ if ( isTrashed || gistId ) {
219
+ if ( confirmDeleteNote ( confirmDeletion , true , gistId ) ) {
206
220
const { note, dispatch} = this . props
207
221
dataApi
208
222
. deleteNote ( note . storage , note . key )
@@ -233,6 +247,26 @@ class SnippetNoteDetail extends React.Component {
233
247
}
234
248
}
235
249
250
+ handleGistedClick ( e ) {
251
+ const { note } = this . state
252
+ note . isGisted = ! note . isGisted
253
+ this . setState ( {
254
+ note
255
+ } , ( ) => {
256
+ this . save ( )
257
+ } )
258
+ ! note . gistId ? getGithubApi ( CREATE_SINGLE_GIST ) ( mapToGist ( note ) ) . then ( x => {
259
+ note . gistId = x . id
260
+ this . setState ( {
261
+ note
262
+ } , ( ) => {
263
+ this . save ( )
264
+ } )
265
+ } ) . catch ( x => {
266
+ throw Error ( x )
267
+ } ) : null
268
+ }
269
+
236
270
handleUndoButtonClick ( e ) {
237
271
const { note } = this . state
238
272
@@ -759,9 +793,12 @@ class SnippetNoteDetail extends React.Component {
759
793
</ div >
760
794
< div styleName = 'info-right' >
761
795
< PermanentDeleteButton onClick = { ( e ) => this . handleTrashButtonClick ( e ) } />
796
+
797
+ < GistButton onClick = { ( e ) => this . handleGistedClick ( e ) } gistId = { note . gistId } isGisted = { note . isGisted } />
762
798
< InfoButton
763
799
onClick = { ( e ) => this . handleInfoButtonClick ( e ) }
764
800
/>
801
+
765
802
< InfoPanelTrashed
766
803
storageName = { currentOption . storage . name }
767
804
folderName = { currentOption . folder . name }
@@ -805,6 +842,8 @@ class SnippetNoteDetail extends React.Component {
805
842
806
843
< TrashButton onClick = { ( e ) => this . handleTrashButtonClick ( e ) } />
807
844
845
+ < GistButton onClick = { ( e ) => this . handleGistedClick ( e ) } gistId = { note . gistId } isGisted = { note . isGisted } />
846
+
808
847
< InfoButton
809
848
onClick = { ( e ) => this . handleInfoButtonClick ( e ) }
810
849
/>
0 commit comments