Mailspring/internal_packages/attachments/lib/attachment-component.cjsx
Evan Morikawa e3dfbe59be refactor(react): convert to class-based React components
Summary: Fix react upgrade errors

Test Plan: edgehill --test

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://review.inboxapp.com/D1456
2015-04-30 13:08:29 -07:00

72 lines
2.2 KiB
CoffeeScript

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
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