path = require 'path'
React = require 'react'
{Actions} = require 'inbox-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
module.exports =
MessageAttachment = React.createClass
displayName: 'MessageAttachment'
propTypes:
file: React.PropTypes.object.isRequired,
download: React.PropTypes.object
getInitialState: ->
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"