{Utils,
React,
ReactDOM,
Actions,
RegExpUtils,
IdentityStore,
AccountStore,
EdgehillAPI} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'
EmailPopover = require './email-popover'
PGPKeyStore = require './pgp-key-store'
KeybaseUser = require '../lib/keybase-user'
Identity = require './identity'
kb = require './keybase'
_ = require 'underscore'
class KeybaseInviteButton extends React.Component
constructor: (@props) ->
@state = {
loading: false,
}
_onGetKeybaseInvite: =>
@setState({loading: true})
errorHandler = (err) =>
@setState({loading: false})
NylasEnv.showErrorDialog(err.message)
EdgehillAPI.makeRequest
authWithNylasAPI: true
path: "/keybase-invite",
method: "POST",
body:
n1_id: IdentityStore.identityId(),
error: errorHandler,
success: (body, response) =>
@setState({loading: false})
try
if not (body instanceof Object) or not body.invite_url
throw new Error("We were unable to retrieve an invitation.")
catch err
errorHandler(err)
require('electron').shell.openExternal(body.invite_url)
render: =>
if @state.loading
Processing...
else
We've got an invite for you!
module.exports =
class KeybaseSearch extends React.Component
@displayName: 'KeybaseSearch'
@propTypes:
initialSearch: React.PropTypes.string
# importFunc: a alternate function to execute when the "import" button is
# clicked instead of the "please specify an email" popover
importFunc: React.PropTypes.func
# TODO consider just passing in a pre-specified email instead of a func?
inPreferences: React.PropTypes.bool
@defaultProps:
initialSearch: ""
importFunc: null
inPreferences: false
constructor: (props) ->
super(props)
@state = {
query: props.initialSearch
results: []
loading: false
searchedByEmail: false
}
@debouncedSearch = _.debounce(@_search, 300)
componentDidMount: ->
@_search()
componentWillReceiveProps: (props) ->
@setState({query: props.initialSearch})
_search: ->
oldquery = @state.query
if @state.query != "" and @state.loading == false
@setState({loading: true})
kb.autocomplete(@state.query, (error, profiles) =>
if profiles?
profiles = _.map(profiles, (profile) ->
return new Identity({keybase_profile: profile, isPriv: false})
)
@setState({results: profiles, loading: false})
else
@setState({results: [], loading: false})
if @state.query != oldquery
@debouncedSearch()
)
else
# no query - empty out the results
@setState({results: []})
_importKey: (profile, event) =>
# opens a popover requesting user to enter 1+ emails to associate with a
# key - a button in the popover then calls _save to actually import the key
popoverTarget = event.target.getBoundingClientRect()
Actions.openPopover(
Try entering a name, or a username from GitHub, Keybase or Twitter.
if @state.loading
loading =
Not a Keybase user yet?