path = require 'path' React = require 'react' {Actions} = require 'nylas-exports' # Passed in as props from MessageItem and FileDownloadStore # This is empty if the attachment isn't downloading. # @props.download is a FileDownloadStore.Download object # @props.file is a File object class AttachmentComponent extends React.Component @displayName: 'AttachmentComponent' @propTypes: file: React.PropTypes.object.isRequired, download: React.PropTypes.object constructor: (@props) -> @state = progressPercent: 0 render: =>
  {@props.file.filename} {@_fileActions()}
_fileActions: => if @props.removable else if @_isDownloading() else _downloadProgressStyle: => width: @props.download?.percent ? 0 _onClickRemove: => Actions.removeFile file: @props.file messageLocalId: @props.messageLocalId _onClickView: => Actions.fetchAndOpenFile(@props.file) if @_canClickToView() _onClickDownload: => Actions.fetchAndSaveFile(@props.file) _onClickAbort: => Actions.abortDownload(@props.file, @props.download) _canClickToView: => not @props.removable and not @_isDownloading() _isDownloading: => @props.download?.state() is "downloading" module.exports = AttachmentComponent