path = require 'path' React = require 'react' {Actions, FileUploadStore} = require 'inbox-exports' class FileUpload extends React.Component render: =>
  {@_basename()}
_uploadProgressStyle: => if @props.uploadData.fileSize <= 0 percent = 0 else percent = (@props.uploadData.bytesUploaded / @props.uploadData.fileSize) * 100 width: "#{percent}%" _onClickRemove: => Actions.abortUpload @props.uploadData _basename: => path.basename(@props.uploadData.filePath) class FileUploads extends React.Component constructor: (@props) -> @state = uploads: FileUploadStore.uploadsForMessage(@props.localId) ? [] componentDidMount: => @storeUnlisten = FileUploadStore.listen(@_onFileUploadStoreChange) componentWillUnmount: => @storeUnlisten() if @storeUnlisten render: => {@_fileUploads()} _fileUploads: => @state.uploads.map (uploadData) => _key: (uploadData) => "#{uploadData.messageLocalId} #{uploadData.filePath}" # fileUploads: # "some_local_msg_id /some/full/path/name": # messageLocalId - The localId of the message (draft) we're uploading to # filePath - The full absolute local system file path # fileSize - The size in bytes # fileName - The basename of the file # bytesUploaded - Current number of bytes uploaded # state - one of "started" "progress" "completed" "aborted" "failed" _onFileUploadStoreChange: => @setState uploads: FileUploadStore.uploadsForMessage(@props.localId) module.exports = FileUploads