From 424965f8763ec451069062a5c319ae929c8d52c2 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 13 Apr 2018 16:25:52 -0400 Subject: [PATCH] :art: Autoformat code --- ts/GoogleChrome.ts | 8 +- .../media-gallery/AttachmentListSection.tsx | 19 ++-- .../media-gallery/DocumentListEntry.tsx | 26 ++--- .../media-gallery/ImageThumbnail.tsx | 11 +-- .../media-gallery/LoadingIndicator.tsx | 3 + .../media-gallery/MediaGallery.tsx | 24 +++-- .../media-gallery/groupMessagesByDate.ts | 21 ++-- .../media-gallery/propTypes/Message.tsx | 3 + ts/missingCaseError.ts | 3 + .../media-gallery/groupMessagesByDate.ts | 10 +- ts/types/Attachment.ts | 4 +- ts/types/Conversation.ts | 23 +++-- ts/types/MIME.ts | 16 ++-- ts/types/Message.ts | 95 +++++++++++-------- .../message/initializeAttachmentMetadata.ts | 32 ++++--- 15 files changed, 158 insertions(+), 140 deletions(-) diff --git a/ts/GoogleChrome.ts b/ts/GoogleChrome.ts index 9d9429ca4..7d31c7249 100644 --- a/ts/GoogleChrome.ts +++ b/ts/GoogleChrome.ts @@ -1,6 +1,8 @@ +/** + * @prettier + */ import * as MIME from './types/MIME'; - interface MIMETypeSupportMap { [key: string]: boolean; } @@ -24,7 +26,7 @@ const SUPPORTED_IMAGE_MIME_TYPES: MIMETypeSupportMap = { }; export const isImageTypeSupported = (mimeType: MIME.MIMEType): boolean => - SUPPORTED_IMAGE_MIME_TYPES[mimeType] === true; + SUPPORTED_IMAGE_MIME_TYPES[mimeType] === true; const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = { 'video/mp4': true, @@ -34,4 +36,4 @@ const SUPPORTED_VIDEO_MIME_TYPES: MIMETypeSupportMap = { // See: https://www.chromium.org/audio-video export const isVideoTypeSupported = (mimeType: MIME.MIMEType): boolean => - SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true; + SUPPORTED_VIDEO_MIME_TYPES[mimeType] === true; diff --git a/ts/components/conversation/media-gallery/AttachmentListSection.tsx b/ts/components/conversation/media-gallery/AttachmentListSection.tsx index 65c58aa95..1be2b0f9a 100644 --- a/ts/components/conversation/media-gallery/AttachmentListSection.tsx +++ b/ts/components/conversation/media-gallery/AttachmentListSection.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ import React from 'react'; import { DocumentListEntry } from './DocumentListEntry'; @@ -5,13 +8,11 @@ import { ImageThumbnail } from './ImageThumbnail'; import { Message } from './propTypes/Message'; import { missingCaseError } from '../../../missingCaseError'; - const styles = { container: { width: '100%', }, - header: { - }, + header: {}, itemContainer: { display: 'flex', flexDirection: 'row', @@ -32,18 +33,14 @@ export class AttachmentListSection extends React.Component { public renderItems() { const { i18n, messages, type } = this.props; - return messages.map((message) => { + return messages.map(message => { const { attachments } = message; const firstAttachment = attachments[0]; switch (type) { case 'media': return ( - + ); case 'documents': return ( @@ -67,9 +64,7 @@ export class AttachmentListSection extends React.Component { return (
{header}
-
- {this.renderItems()} -
+
{this.renderItems()}
); } diff --git a/ts/components/conversation/media-gallery/DocumentListEntry.tsx b/ts/components/conversation/media-gallery/DocumentListEntry.tsx index 19c586c63..7b94ee960 100644 --- a/ts/components/conversation/media-gallery/DocumentListEntry.tsx +++ b/ts/components/conversation/media-gallery/DocumentListEntry.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ import React from 'react'; import moment from 'moment'; @@ -5,7 +8,6 @@ import formatFileSize from 'filesize'; // import { LoadingIndicator } from './LoadingIndicator'; - interface Props { fileName?: string; fileSize?: number; @@ -59,28 +61,20 @@ export class DocumentListEntry extends React.Component { // } return ( -
+
-
+
{fileName} - + {typeof fileSize === 'number' ? formatFileSize(fileSize) : ''}
-
+
{moment(timestamp).format('ddd, MMM D, Y')}
@@ -88,10 +82,6 @@ export class DocumentListEntry extends React.Component { } public render() { - return ( -
- {this.renderContent()} -
- ); + return
{this.renderContent()}
; } } diff --git a/ts/components/conversation/media-gallery/ImageThumbnail.tsx b/ts/components/conversation/media-gallery/ImageThumbnail.tsx index 9a774373b..afe802ed5 100644 --- a/ts/components/conversation/media-gallery/ImageThumbnail.tsx +++ b/ts/components/conversation/media-gallery/ImageThumbnail.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ import React from 'react'; import { LoadingIndicator } from './LoadingIndicator'; @@ -27,7 +30,7 @@ const styles = { export class ImageThumbnail extends React.Component { public renderContent() { - const {/* i18n, */message } = this.props; + const { /* i18n, */ message } = this.props; if (!message.objectURL) { return ; @@ -45,10 +48,6 @@ export class ImageThumbnail extends React.Component { } public render() { - return ( -
- {this.renderContent()} -
- ); + return
{this.renderContent()}
; } } diff --git a/ts/components/conversation/media-gallery/LoadingIndicator.tsx b/ts/components/conversation/media-gallery/LoadingIndicator.tsx index 349560a8e..e2bfd4a85 100644 --- a/ts/components/conversation/media-gallery/LoadingIndicator.tsx +++ b/ts/components/conversation/media-gallery/LoadingIndicator.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ import React from 'react'; export const LoadingIndicator = () => { diff --git a/ts/components/conversation/media-gallery/MediaGallery.tsx b/ts/components/conversation/media-gallery/MediaGallery.tsx index 0d24021dd..f5cf64b70 100644 --- a/ts/components/conversation/media-gallery/MediaGallery.tsx +++ b/ts/components/conversation/media-gallery/MediaGallery.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ import React from 'react'; import moment from 'moment'; @@ -7,7 +10,6 @@ import { AttachmentListSection } from './AttachmentListSection'; import { groupMessagesByDate } from './groupMessagesByDate'; import { Message } from './propTypes/Message'; - type AttachmentType = 'media' | 'documents'; interface Props { @@ -58,13 +60,12 @@ const Tab = ({ onSelect, type, }: { - isSelected: boolean, - label: string, - onSelect?: (event: TabSelectEvent) => void, - type: AttachmentType, + isSelected: boolean; + label: string; + onSelect?: (event: TabSelectEvent) => void; + type: AttachmentType; }) => { - const handleClick = onSelect ? - () => onSelect({ type }) : undefined; + const handleClick = onSelect ? () => onSelect({ type }) : undefined; return (
{ public state: State = { selectedTab: 'media', @@ -101,16 +101,14 @@ export class MediaGallery extends React.Component { onSelect={this.handleTabSelect} />
-
- {this.renderSections()} -
+
{this.renderSections()}
); } private handleTabSelect = (event: TabSelectEvent): void => { - this.setState({selectedTab: event.type}); - } + this.setState({ selectedTab: event.type }); + }; private renderSections() { const { i18n, media, documents } = this.props; diff --git a/ts/components/conversation/media-gallery/groupMessagesByDate.ts b/ts/components/conversation/media-gallery/groupMessagesByDate.ts index f0d53824b..c1c9fd1c0 100644 --- a/ts/components/conversation/media-gallery/groupMessagesByDate.ts +++ b/ts/components/conversation/media-gallery/groupMessagesByDate.ts @@ -1,18 +1,25 @@ +/** + * @prettier + */ import moment from 'moment'; -import { groupBy, sortBy } from 'lodash'; +import { compact, groupBy, sortBy } from 'lodash'; import { Message } from './propTypes/Message'; - -export const groupMessagesByDate = (timestamp: number, messages: Array): any => { +export const groupMessagesByDate = ( + timestamp: number, + messages: Array +): any => { const referenceDateTime = moment.utc(timestamp); const today = moment(referenceDateTime).startOf('day'); - const yesterday = moment(referenceDateTime).subtract(1, 'day').startOf('day'); + const yesterday = moment(referenceDateTime) + .subtract(1, 'day') + .startOf('day'); const thisWeek = moment(referenceDateTime).startOf('isoWeek'); const thisMonth = moment(referenceDateTime).startOf('month'); - const sorted = sortBy(messages, (message) => -message.received_at); - const annotations = sorted.map((message) => { + const sorted = sortBy(messages, message => -message.received_at); + const annotations = sorted.map(message => { const date = moment.utc(message.received_at); if (date.isAfter(today)) { @@ -42,7 +49,7 @@ export const groupMessagesByDate = (timestamp: number, messages: Array) } return { - order: (date.year() * 100) + date.month(), + order: date.year() * 100 + date.month(), label: 'yearMonth', message, }; diff --git a/ts/components/conversation/media-gallery/propTypes/Message.tsx b/ts/components/conversation/media-gallery/propTypes/Message.tsx index 209fc2565..6ca64618c 100644 --- a/ts/components/conversation/media-gallery/propTypes/Message.tsx +++ b/ts/components/conversation/media-gallery/propTypes/Message.tsx @@ -1,3 +1,6 @@ +/** + * @prettier + */ export interface Message { id: string; body?: string; diff --git a/ts/missingCaseError.ts b/ts/missingCaseError.ts index c32999bac..cadc49b6d 100644 --- a/ts/missingCaseError.ts +++ b/ts/missingCaseError.ts @@ -1,3 +1,6 @@ +/** + * @prettier + */ // `missingCaseError` is useful for compile-time checking that all `case`s in // a `switch` statement have been handled, e.g. // diff --git a/ts/test/components/media-gallery/groupMessagesByDate.ts b/ts/test/components/media-gallery/groupMessagesByDate.ts index a44258e2a..b74218686 100644 --- a/ts/test/components/media-gallery/groupMessagesByDate.ts +++ b/ts/test/components/media-gallery/groupMessagesByDate.ts @@ -1,11 +1,11 @@ +/** + * @prettier + */ import 'mocha'; import { assert } from 'chai'; -import { groupMessagesByDate } from - '../../../components/conversation/media-gallery/groupMessagesByDate'; -import { Message } from - '../../../components/conversation/media-gallery/propTypes/Message'; - +import { groupMessagesByDate } from '../../../components/conversation/media-gallery/groupMessagesByDate'; +import { Message } from '../../../components/conversation/media-gallery/propTypes/Message'; const toMessage = (date: Date): Message => ({ id: date.toUTCString(), diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 44138ae22..c33f6f8c5 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -1,9 +1,11 @@ +/** + * @prettier + */ import is from '@sindresorhus/is'; import * as GoogleChrome from '../GoogleChrome'; import { MIMEType } from './MIME'; - export interface Attachment { fileName?: string; contentType?: MIMEType; diff --git a/ts/types/Conversation.ts b/ts/types/Conversation.ts index e31b3b0a6..360b988f1 100644 --- a/ts/types/Conversation.ts +++ b/ts/types/Conversation.ts @@ -1,7 +1,9 @@ +/** + * @prettier + */ import is from '@sindresorhus/is'; import { Message } from './Message'; - interface ConversationLastMessageUpdate { lastMessage: string | null; timestamp: number | null; @@ -13,10 +15,10 @@ export const createLastMessageUpdate = ({ lastMessage, lastMessageNotificationText, }: { - currentLastMessageText: string | null, - currentTimestamp: number | null, - lastMessage: Message | null, - lastMessageNotificationText: string | null, + currentLastMessageText: string | null; + currentTimestamp: number | null; + lastMessage: Message | null; + lastMessageNotificationText: string | null; }): ConversationLastMessageUpdate => { if (lastMessage === null) { return { @@ -30,13 +32,14 @@ export const createLastMessageUpdate = ({ const isExpiringMessage = is.object(lastMessage.expirationTimerUpdate); const shouldUpdateTimestamp = !isVerifiedChangeMessage && !isExpiringMessage; - const newTimestamp = shouldUpdateTimestamp ? - lastMessage.sent_at : - currentTimestamp; + const newTimestamp = shouldUpdateTimestamp + ? lastMessage.sent_at + : currentTimestamp; const shouldUpdateLastMessageText = !isVerifiedChangeMessage; - const newLastMessageText = shouldUpdateLastMessageText ? - lastMessageNotificationText : currentLastMessageText; + const newLastMessageText = shouldUpdateLastMessageText + ? lastMessageNotificationText + : currentLastMessageText; return { lastMessage: newLastMessageText, diff --git a/ts/types/MIME.ts b/ts/types/MIME.ts index 3ac85dbfb..a27cb658c 100644 --- a/ts/types/MIME.ts +++ b/ts/types/MIME.ts @@ -1,14 +1,12 @@ +/** + * @prettier + */ export type MIMEType = string & { _mimeTypeBrand: any }; +export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg'; -export const isJPEG = (value: MIMEType): boolean => - value === 'image/jpeg'; +export const isImage = (value: MIMEType): boolean => value.startsWith('image/'); -export const isImage = (value: MIMEType): boolean => - value.startsWith('image/'); +export const isVideo = (value: MIMEType): boolean => value.startsWith('video/'); -export const isVideo = (value: MIMEType): boolean => - value.startsWith('video/'); - -export const isAudio = (value: MIMEType): boolean => - value.startsWith('audio/'); +export const isAudio = (value: MIMEType): boolean => value.startsWith('audio/'); diff --git a/ts/types/Message.ts b/ts/types/Message.ts index 4afe2dc84..2b5828edb 100644 --- a/ts/types/Message.ts +++ b/ts/types/Message.ts @@ -1,52 +1,63 @@ +/** + * @prettier + */ import { Attachment } from './Attachment'; +export type Message = IncomingMessage | OutgoingMessage | VerifiedChangeMessage; -export type Message - = IncomingMessage - | OutgoingMessage - | VerifiedChangeMessage; +export type IncomingMessage = Readonly< + { + type: 'incoming'; + // Required + attachments: Array; + id: string; + received_at: number; -export type IncomingMessage = Readonly<{ - type: 'incoming'; - // Required - attachments: Array; - id: string; - received_at: number; + // Optional + body?: string; + decrypted_at?: number; + errors?: Array; + flags?: number; + source?: string; + sourceDevice?: number; + } & SharedMessageProperties & + Message4 & + ExpirationTimerUpdate +>; - // Optional - body?: string; - decrypted_at?: number; - errors?: Array; - flags?: number; - source?: string; - sourceDevice?: number; -} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>; +export type OutgoingMessage = Readonly< + { + type: 'outgoing'; -export type OutgoingMessage = Readonly<{ - type: 'outgoing'; + // Required + attachments: Array; + delivered: number; + delivered_to: Array; + destination: string; // PhoneNumber + expirationStartTimestamp: number; + id: string; + received_at: number; + sent: boolean; + sent_to: Array; // Array - // Required - attachments: Array; - delivered: number; - delivered_to: Array; - destination: string; // PhoneNumber - expirationStartTimestamp: number; - id: string; - received_at: number; - sent: boolean; - sent_to: Array; // Array + // Optional + body?: string; + expires_at?: number; + expireTimer?: number; + recipients?: Array; // Array + synced: boolean; + } & SharedMessageProperties & + Message4 & + ExpirationTimerUpdate +>; - // Optional - body?: string; - expires_at?: number; - expireTimer?: number; - recipients?: Array; // Array - synced: boolean; -} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>; - -export type VerifiedChangeMessage = Readonly<{ - type: 'verified-change'; -} & SharedMessageProperties & Message4 & ExpirationTimerUpdate>; +export type VerifiedChangeMessage = Readonly< + { + type: 'verified-change'; + } & SharedMessageProperties & + Message4 & + ExpirationTimerUpdate +>; type SharedMessageProperties = Readonly<{ conversationId: string; @@ -59,7 +70,7 @@ type ExpirationTimerUpdate = Readonly<{ expireTimer: number; fromSync: boolean; source: string; // PhoneNumber - }>, + }>; }>; type Message4 = Readonly<{ diff --git a/ts/types/message/initializeAttachmentMetadata.ts b/ts/types/message/initializeAttachmentMetadata.ts index 49d0f35d6..084f1e1ad 100644 --- a/ts/types/message/initializeAttachmentMetadata.ts +++ b/ts/types/message/initializeAttachmentMetadata.ts @@ -1,20 +1,24 @@ +/** + * @prettier + */ import { partition } from 'lodash'; import * as Attachment from '../Attachment'; -import { Message } from '../message'; +import { Message } from '../Message'; +export const initializeAttachmentMetadata = async ( + message: Message +): Promise => { + const numAttachments = message.attachments.length; + const [numVisualMediaAttachments, numFileAttachments] = partition( + message.attachments, + Attachment.isVisualMedia + ).map(attachments => attachments.length); -export const initializeAttachmentMetadata = - async (message: Message): Promise => { - const numAttachments = message.attachments.length; - const [numVisualMediaAttachments, numFileAttachments] = - partition(message.attachments, Attachment.isVisualMedia) - .map((attachments) => attachments.length); - - return { - ...message, - numAttachments, - numVisualMediaAttachments, - numFileAttachments, - }; + return { + ...message, + numAttachments, + numVisualMediaAttachments, + numFileAttachments, }; +};