_ = require 'underscore' path = require 'path' React = require 'react' {RetinaImg} = require 'nylas-component-kit' {Actions, Utils} = 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 removable: React.PropTypes.boolean targetPath: React.PropTypes.string messageLocalId: React.PropTypes.string constructor: (@props) -> @state = progressPercent: 0 render: =>
{@_fileActions()} {@props.file.filename}
_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" _extension: -> @props.file.filename.split('.').pop() module.exports = AttachmentComponent