Mailspring/internal_packages/attachments/lib/attachment-component.cjsx
Ben Gotow 9378f4480c fix(naming): Move atom/inbox/nilas refs to Nylas
Conflicts:
	internal_packages/inbox-activity-bar/lib/activity-bar-long-poll-item.cjsx
2015-05-15 11:07:28 -07:00

71 lines
2.2 KiB
CoffeeScript

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: =>
<div className={"attachment-file-wrap " + (@props.download?.state() ? "")}>
<span className="attachment-download-bar-wrap">
<span className="attachment-bar-bg"></span>
<span className="attachment-download-progress" style={@_downloadProgressStyle()}></span>
</span>
<span className="attachment-file-and-name" onClick={@_onClickView}>
<span className="attachment-file-icon"><i className="fa fa-file-o"></i>&nbsp;</span>
<span className="attachment-file-name">{@props.file.filename}</span>
</span>
<span className="attachment-file-actions">
{@_fileActions()}
</span>
</div>
_fileActions: =>
if @props.removable
<button className="btn btn-icon attachment-icon" onClick={@_onClickRemove}>
<i className="fa fa-remove"></i>
</button>
else if @_isDownloading()
<button className="btn btn-icon attachment-icon" onClick={@_onClickAbort}>
<i className="fa fa-remove"></i>
</button>
else
<button className="btn btn-icon attachment-icon" onClick={@_onClickDownload}>
<i className="fa fa-download"></i>
</button>
_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