diff --git a/internal_packages/attachments/lib/attachment-component.cjsx b/internal_packages/attachments/lib/attachment-component.cjsx index 716991a39..5fa8ad35c 100644 --- a/internal_packages/attachments/lib/attachment-component.cjsx +++ b/internal_packages/attachments/lib/attachment-component.cjsx @@ -28,7 +28,7 @@ class AttachmentComponent extends React.Component + name="file-#{@props.file.displayExtension()}.png"/> {@props.file.displayName()} {@_renderFileActions()} @@ -89,7 +89,5 @@ class AttachmentComponent extends React.Component Actions.abortFetchFile(@props.file) event.stopPropagation() # Prevent 'onClickView' - _extension: -> @props.file.filename.split('.').pop() - module.exports = AttachmentComponent diff --git a/internal_packages/composer/lib/file-upload.cjsx b/internal_packages/composer/lib/file-upload.cjsx index 5f572f527..7e1589056 100644 --- a/internal_packages/composer/lib/file-upload.cjsx +++ b/internal_packages/composer/lib/file-upload.cjsx @@ -43,6 +43,7 @@ class FileUpload extends React.Component _basename: => path.basename(@props.uploadData.filePath) - _extension: -> path.extname(@_basename()).split('.').pop() + _extension: => + path.extname(@_basename())[1..-1] module.exports = FileUpload diff --git a/spec-nylas/models/file-spec.coffee b/spec-nylas/models/file-spec.coffee index b32f2bcf9..1cd98f445 100644 --- a/spec-nylas/models/file-spec.coffee +++ b/spec-nylas/models/file-spec.coffee @@ -1,6 +1,43 @@ +File = require '../../src/flux/models/file' test_file_path = "/path/to/file.jpg" describe "File", -> it "attempts to generate a new file upload task on creation", -> # File.create(test_file_path) + + describe "displayName", -> + it "should return the filename if populated", -> + f = new File(filename: 'Hello world.jpg', contentType: 'image/jpg') + expect(f.displayName()).toBe('Hello world.jpg') + f = new File(filename: 'a', contentType: 'image/jpg') + expect(f.displayName()).toBe('a') + + it "should return a good default name if a content type is populated", -> + f = new File(filename: '', contentType: 'image/jpg') + expect(f.displayName()).toBe('Unnamed Image.jpg') + f = new File(filename: null, contentType: 'image/jpg') + expect(f.displayName()).toBe('Unnamed Image.jpg') + f = new File(filename: null, contentType: 'text/calendar') + expect(f.displayName()).toBe('Event.ics') + + it "should return Unnamed Attachment otherwise", -> + f = new File(filename: '', contentType: null) + expect(f.displayName()).toBe('Unnamed Attachment') + f = new File(filename: null, contentType: '') + expect(f.displayName()).toBe('Unnamed Attachment') + f = new File(filename: null, contentType: null) + expect(f.displayName()).toBe('Unnamed Attachment') + + describe "displayExtension", -> + it "should return an extension based on the filename when populated", -> + f = new File(filename: 'Hello world.jpg', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('jpg') + f = new File(filename: 'a', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('') + + it "should return an extension based on the default filename otherwise", -> + f = new File(filename: '', contentType: 'image/jpg') + expect(f.displayExtension()).toBe('jpg') + f = new File(filename: null, contentType: 'text/calendar') + expect(f.displayExtension()).toBe('ics') diff --git a/spec-nylas/stores/event-store-spec.coffee b/spec-nylas/stores/event-store-spec.coffee index b2f5a47cb..56662d81b 100644 --- a/spec-nylas/stores/event-store-spec.coffee +++ b/spec-nylas/stores/event-store-spec.coffee @@ -62,4 +62,4 @@ describe "EventStore", -> third = EventStore.getEvent(3) expect(third.title).toBe 'Test3' fourth = EventStore.getEvent(4) - expect(fourth.title).toBe 'Test4' \ No newline at end of file + expect(fourth.title).toBe 'Test4' diff --git a/src/flux/models/file.coffee b/src/flux/models/file.coffee index c645a7e69..8da80ab0a 100644 --- a/src/flux/models/file.coffee +++ b/src/flux/models/file.coffee @@ -1,3 +1,4 @@ +path = require 'path' Model = require './model' Actions = require '../actions' Attributes = require '../attributes' @@ -66,4 +67,13 @@ class File extends Model else return "Unnamed Attachment" + # Public: Returns the file extension that should be used for this file. + # Note that asking for the displayExtension is more accurate than trying to read + # the extension directly off the filename, and may be based on contentType. + # + # Returns the extension without the leading '.' (ex: 'png', 'pdf') + # + displayExtension: -> + path.extname(@displayName())[1..-1] + module.exports = File diff --git a/static/images/attachments/file-doc@2x.png b/static/images/attachments/file-doc@2x.png index 245ba46bd..9bed6d792 100644 Binary files a/static/images/attachments/file-doc@2x.png and b/static/images/attachments/file-doc@2x.png differ diff --git a/static/images/attachments/file-docx@2x.png b/static/images/attachments/file-docx@2x.png index 245ba46bd..9bed6d792 100644 Binary files a/static/images/attachments/file-docx@2x.png and b/static/images/attachments/file-docx@2x.png differ diff --git a/static/images/attachments/file-fallback@2x.png b/static/images/attachments/file-fallback@2x.png index 7014a9905..f05ba9631 100644 Binary files a/static/images/attachments/file-fallback@2x.png and b/static/images/attachments/file-fallback@2x.png differ diff --git a/static/images/attachments/file-ics@2x.png b/static/images/attachments/file-ics@2x.png new file mode 100644 index 000000000..865b20509 Binary files /dev/null and b/static/images/attachments/file-ics@2x.png differ diff --git a/static/images/attachments/file-pdf@2x.png b/static/images/attachments/file-pdf@2x.png index 2274c3b2f..bcb4c60f5 100644 Binary files a/static/images/attachments/file-pdf@2x.png and b/static/images/attachments/file-pdf@2x.png differ diff --git a/static/images/attachments/file-ppt@2x.png b/static/images/attachments/file-ppt@2x.png new file mode 100644 index 000000000..1a5070280 Binary files /dev/null and b/static/images/attachments/file-ppt@2x.png differ diff --git a/static/images/attachments/file-pptx@2x.png b/static/images/attachments/file-pptx@2x.png new file mode 100644 index 000000000..1a5070280 Binary files /dev/null and b/static/images/attachments/file-pptx@2x.png differ diff --git a/static/images/attachments/file-xls@2x.png b/static/images/attachments/file-xls@2x.png new file mode 100644 index 000000000..013a63066 Binary files /dev/null and b/static/images/attachments/file-xls@2x.png differ diff --git a/static/images/attachments/file-xlsx@2x.png b/static/images/attachments/file-xlsx@2x.png new file mode 100644 index 000000000..013a63066 Binary files /dev/null and b/static/images/attachments/file-xlsx@2x.png differ diff --git a/static/images/attachments/file-zip@2x.png b/static/images/attachments/file-zip@2x.png index 6b5b205c7..2e4d25c12 100644 Binary files a/static/images/attachments/file-zip@2x.png and b/static/images/attachments/file-zip@2x.png differ