@@ -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,15 @@ class SnippetNoteDetail extends React.Component {
146
154
} )
147
155
}
148
156
157
+ saveGithub ( ) {
158
+ console . log ( 'now' )
159
+
160
+ const { note } = this . props
161
+ clearTimeout ( this . saveGithubQueue )
162
+ this . saveGithubQueue = null
163
+ getGithubApi ( EDIT_SINGLE_GIST ) ( mapToGist ( note ) )
164
+ }
165
+
149
166
handleFolderChange ( e ) {
150
167
const { note } = this . state
151
168
const value = this . refs . folder . value
@@ -198,11 +215,10 @@ class SnippetNoteDetail extends React.Component {
198
215
199
216
handleTrashButtonClick ( e ) {
200
217
const { note } = this . state
201
- const { isTrashed } = note
218
+ const { isTrashed, gistId } = note
202
219
const { confirmDeletion } = this . props . config . ui
203
-
204
- if ( isTrashed ) {
205
- if ( confirmDeleteNote ( confirmDeletion , true ) ) {
220
+ if ( isTrashed || gistId ) {
221
+ if ( confirmDeleteNote ( confirmDeletion , true , gistId ) ) {
206
222
const { note, dispatch} = this . props
207
223
dataApi
208
224
. deleteNote ( note . storage , note . key )
@@ -233,6 +249,26 @@ class SnippetNoteDetail extends React.Component {
233
249
}
234
250
}
235
251
252
+ handleGistedClick ( e ) {
253
+ const { note } = this . state
254
+ note . isGisted = ! note . isGisted
255
+ this . setState ( {
256
+ note
257
+ } , ( ) => {
258
+ this . save ( )
259
+ } )
260
+ ! note . gistId ? getGithubApi ( CREATE_SINGLE_GIST ) ( mapToGist ( note ) ) . then ( x => {
261
+ note . gistId = x . id
262
+ this . setState ( {
263
+ note
264
+ } , ( ) => {
265
+ this . save ( )
266
+ } )
267
+ } ) . catch ( x => {
268
+ throw Error ( x )
269
+ } ) : null
270
+ }
271
+
236
272
handleUndoButtonClick ( e ) {
237
273
const { note } = this . state
238
274
@@ -759,9 +795,12 @@ class SnippetNoteDetail extends React.Component {
759
795
</ div >
760
796
< div styleName = 'info-right' >
761
797
< PermanentDeleteButton onClick = { ( e ) => this . handleTrashButtonClick ( e ) } />
798
+
799
+ < GistButton onClick = { ( e ) => this . handleGistedClick ( e ) } gistId = { note . gistId } isGisted = { note . isGisted } />
762
800
< InfoButton
763
801
onClick = { ( e ) => this . handleInfoButtonClick ( e ) }
764
802
/>
803
+
765
804
< InfoPanelTrashed
766
805
storageName = { currentOption . storage . name }
767
806
folderName = { currentOption . folder . name }
@@ -805,6 +844,8 @@ class SnippetNoteDetail extends React.Component {
805
844
806
845
< TrashButton onClick = { ( e ) => this . handleTrashButtonClick ( e ) } />
807
846
847
+ < GistButton onClick = { ( e ) => this . handleGistedClick ( e ) } gistId = { note . gistId } isGisted = { note . isGisted } />
848
+
808
849
< InfoButton
809
850
onClick = { ( e ) => this . handleInfoButtonClick ( e ) }
810
851
/>
0 commit comments