From 4d08a74d532f040234dc67388872e681c5e15562 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 13 Nov 2018 10:56:30 +1100 Subject: [PATCH] Updated FriendRequest to be more consistent with the other typescript components. --- _locales/en/messages.json | 10 +-- js/models/messages.js | 4 +- ts/components/conversation/FriendRequest.md | 34 +++++++++ ts/components/conversation/FriendRequest.tsx | 79 ++++++++++++++------ 4 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 ts/components/conversation/FriendRequest.md diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 9f0c0362c..c3bf9d532 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1578,13 +1578,9 @@ } } }, - "incomingFriendRequestPending": { - "message": "Friend request received", - "description": "Shown in the conversation history when the user recieves a friend request" - }, - "outgoingFriendRequestPending": { - "message": "Friend request sent", - "description": "Shown in the conversation history when the user sends a friend request" + "friendRequestPending": { + "message": "Friend request", + "description": "Shown in the conversation history when the user sends or recieves a friend request" }, "friendRequestAccepted": { "message": "Friend request accepted", diff --git a/js/models/messages.js b/js/models/messages.js index 238b23ea7..f28023fd6 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -324,7 +324,7 @@ }); }; - const onDelete = async () => { + const onDeleteConversation = async () => { // Delete the whole conversation window.Whisper.events.trigger('deleteConversation', conversation); }; @@ -336,7 +336,7 @@ friendStatus, onAccept, onDecline, - onDelete, + onDeleteConversation, onRetrySend: () => this.retrySend(), } }, diff --git a/ts/components/conversation/FriendRequest.md b/ts/components/conversation/FriendRequest.md new file mode 100644 index 000000000..650e50bdb --- /dev/null +++ b/ts/components/conversation/FriendRequest.md @@ -0,0 +1,34 @@ +### Friend Requests + +#### Parameters +| Name | Values | +| -------------------- | -------------------------------------------- | +| text | string | +| direction | 'outgoing' \| 'incoming | +| status | 'sending' \| 'sent' \| 'read' \| 'delivered' | +| friendStatus | 'pending' \| 'accepted' \| 'declined' | +| i18n | Localizer | +| onAccept | function | +| onDecline | function | +| onDeleteConversation | function | +| onRetrySend | function | + + +#### Example +```jsx + +
  • + console.log('Accepted friend request')} + onDecline={() => console.log('Declined friend request')} + onDeleteConversation={() => console.log('Delete conversation')} + onRetrySend={() => console.log('Retry sending message')} + /> +
  • +
    +``` diff --git a/ts/components/conversation/FriendRequest.tsx b/ts/components/conversation/FriendRequest.tsx index 1f768e615..5179b631a 100644 --- a/ts/components/conversation/FriendRequest.tsx +++ b/ts/components/conversation/FriendRequest.tsx @@ -5,24 +5,24 @@ import { Localizer } from '../../types/Util'; import { MessageBody } from './MessageBody'; interface Props { - text?: string; + text: string; direction: 'incoming' | 'outgoing'; status: string; - i18n: Localizer; friendStatus: 'pending' | 'accepted' | 'declined'; + i18n: Localizer; onAccept: () => void; onDecline: () => void; - onDelete: () => void; + onDeleteConversation: () => void; onRetrySend: () => void; } export class FriendRequest extends React.Component { public getStringId() { - const { friendStatus, direction } = this.props; + const { friendStatus } = this.props; switch (friendStatus) { case 'pending': - return `${direction}FriendRequestPending`; + return `friendRequestPending`; case 'accepted': return `friendRequestAccepted`; case 'declined': @@ -38,32 +38,44 @@ export class FriendRequest extends React.Component { return (
    -
    {i18n(id)}
    - {!!text && -
    - -
    - } +
    + {i18n(id)} +
    +
    + +
    ); } public renderButtons() { - const { friendStatus, direction, status, onAccept, onDecline, onDelete, onRetrySend } = this.props; + const { friendStatus, direction, status, onAccept, onDecline, onDeleteConversation, onRetrySend } = this.props; if (direction === 'incoming') { if (friendStatus === 'pending') { return ( -
    +
    ); } else if (friendStatus === 'declined') { return ( -
    - +
    +
    ); } @@ -71,7 +83,13 @@ export class FriendRequest extends React.Component { // Render the retry button if we errored if (status === 'error') { return ( -
    +
    ); @@ -100,7 +118,7 @@ export class FriendRequest extends React.Component { } // Renders 'sending', 'read' icons - public renderMetadata() { + public renderStatusIndicator() { const { direction, status } = this.props; if (direction !== 'outgoing' || status === 'error') return null; @@ -110,7 +128,7 @@ export class FriendRequest extends React.Component {
    @@ -120,14 +138,29 @@ export class FriendRequest extends React.Component { public render() { const { direction } = this.props; - // const showRetry = status === 'error' && direction === 'outgoing'; return ( -
    +
    {this.renderError(direction === 'incoming')} -
    -
    +
    +
    {this.renderContents()} - {this.renderMetadata()} + {this.renderStatusIndicator()} {this.renderButtons()}