@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
22import ReactDOM from 'react-dom'
33import api from 'boost/api'
44import clientKey from 'boost/clientKey'
5+ import activityRecord from 'boost/activityRecord'
56const clipboard = require ( 'electron' ) . clipboard
67
78function getDefault ( ) {
@@ -11,7 +12,8 @@ function getDefault () {
1112 // Fetched url
1213 url : null ,
1314 // for tooltip Copy -> Copied!
14- copied : false
15+ copied : false ,
16+ failed : false
1517 }
1618}
1719
@@ -70,14 +72,21 @@ export default class ShareButton extends React.Component {
7072 clientKey : clientKey . get ( ) ,
7173 writerName : user . name
7274 } )
73- api . shareWithPublicURL ( input )
74- . then ( res => {
75- let url = res . body . url
76- this . setState ( { url : url } )
77- } )
78- . catch ( err => {
79- console . log ( err )
80- } )
75+ this . setState ( {
76+ isSharing : true ,
77+ failed : false
78+ } , ( ) => {
79+ api . shareWithPublicURL ( input )
80+ . then ( res => {
81+ let url = res . body . url
82+ this . setState ( { url : url , isSharing : false } )
83+ activityRecord . emit ( 'ARTICLE_SHARE' )
84+ } )
85+ . catch ( err => {
86+ console . log ( err )
87+ this . setState ( { isSharing : false , failed : true } )
88+ } )
89+ } )
8190 }
8291
8392 handleCopyURLClick ( ) {
@@ -109,7 +118,7 @@ export default class ShareButton extends React.Component {
109118 onClick = { e => this . shareWithPublicURLHandler ( e ) }
110119 ref = 'sharePublicURL'
111120 disabled = { this . state . isSharing } >
112- < i className = 'fa fa-fw fa-external-link' /> { ! this . state . isSharing ? 'Share with public URL' : 'Sharing...' }
121+ < i className = 'fa fa-fw fa-external-link' /> { this . state . failed ? 'Failed : Click to Try again' : ! this . state . isSharing ? 'Share with public URL' : 'Sharing...' }
113122 </ button >
114123 ) : (
115124 < div className = 'ShareButton-url' >
0 commit comments