path = require 'path' React = require 'react' {Actions} = require 'inbox-exports' # Passed in as props from MessageItem and FileDownloadStore # Generated in tasks/download-file.coffee # This is empty if the attachment isn't downloading. # @props.downloadData: # state - One of "pending "started" "progress" "completed" "aborted" "failed" # fileId - The id of the file # shellAction - Action used to open the file after downloading # downloadPath - The full path of the download location # total - From request-progress: total number of bytes # percent - From request-progress # received - From request-progress: currently received bytes # # @props.file is a File object module.exports = MessageAttachment = React.createClass displayName: 'MessageAttachment' getInitialState: -> progressPercent: 0 render: ->
  {@props.file.filename} {@_fileActions()}
_fileActions: -> if @props.removable else if @_isDownloading() else _downloadProgressStyle: -> width: @props.downloadData?.percent ? 0 _onClickRemove: -> Actions.removeFile file: @props.file messageLocalId: @props.messageLocalId _onClickView: -> Actions.viewFile(@props.file) if @_canClickToView() _onClickDownload: -> Actions.saveFile @props.file _onClickAbort: -> Actions.abortDownload(@props.file, @props.downloadData) _canClickToView: -> not @props.removable and not @_isDownloading() _showDownload: -> if @_isDownloading() then {display: "block"} else {display: "none"} _isDownloading: -> @props.downloadData?.state in ["pending", "started", "progress"]