Skip to content

Commit 5680284

Browse files
committed
0.1.6
1 parent 6c942e0 commit 5680284

File tree

11 files changed

+90
-7
lines changed

11 files changed

+90
-7
lines changed

src/BeforeMessages.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
import { html, VirtualMessage } from "@talkjs/react-components";
12
/** @import { BeforeMessagesProps } from "@talkjs/react-components"; */
23

34
/**
45
* BeforeMessages is rendered inside the message list container, before the first message.
6+
* By default, it renders `conversation.welcomeMessages` as virtual system messages.
7+
*
58
* @param {BeforeMessagesProps} props
69
*/
710
export function BeforeMessages({ common }) {
8-
return null;
11+
const welcomeMessages = common.conversation.welcomeMessages;
12+
if (welcomeMessages.length === 0) {
13+
return null;
14+
}
15+
16+
const virtualMessages = welcomeMessages.map(
17+
(message, i) => html`<${VirtualMessage} key=${i} text=${message} />`,
18+
);
19+
20+
// We're inside a `flex-direction: column-reverse` container so we render the
21+
// messages in reverse order.
22+
return html`<div className="t-message-group">${virtualMessages.reverse()}</div>`;
923
}

src/ChatHeader.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,33 @@
7676
-webkit-box-shadow: inset 0 0 0 1px rgba(50, 50, 50, 0.4);
7777
box-shadow: inset 0 0 0 1px rgba(50, 50, 50, 0.4);
7878
}
79+
80+
.t-theme-chat-header .t-back-button {
81+
display: none;
82+
83+
margin-left: -0.5em;
84+
margin-right: 0.5em;
85+
width: 36px;
86+
height: 36px;
87+
padding: 0;
88+
border: 0;
89+
border-radius: 9999px;
90+
cursor: pointer;
91+
justify-content: center;
92+
align-items: center;
93+
background: transparent;
94+
color: currentColor;
95+
opacity: 0.75;
96+
transition: 150ms ease-out;
97+
}
98+
99+
.t-theme-chat-header .t-back-button:hover,
100+
.t-theme-chat-header .t-back-button:focus {
101+
background-color: rgba(38 38 38 / 5%);
102+
color: #007df9;
103+
opacity: 1;
104+
}
105+
106+
[t-mobile-inbox] .t-theme-chat-header .t-back-button {
107+
display: inline-flex;
108+
}

src/ChatHeader.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { html, useParticipants } from "@talkjs/react-components";
33

44
/** @param {ChatHeaderProps} props */
55
export function ChatHeader(props) {
6-
const { conversation, theme } = props.common;
6+
const { conversation, theme, chatbox, t } = props.common;
77
const { ConversationImage } = theme;
88

99
const participants = useParticipants(conversation.id, 10);
@@ -12,6 +12,14 @@ export function ChatHeader(props) {
1212
<div className="t-theme-chat-header">
1313
<div className="t-inner">
1414
<div className="t-content">
15+
<button
16+
className="t-back-button"
17+
aria-label=${t.INBOX}
18+
title=${t.INBOX}
19+
onClick=${() => chatbox.clickBackButton()}
20+
>
21+
<${theme.Icon} type="chevronLeft" common=${props.common} />
22+
</button>
1523
<div className="t-image">
1624
<${ConversationImage}
1725
conversation=${conversation}

src/Message.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@
309309
width: 1.143em;
310310
height: 1.143em;
311311
}
312-
.t-message-action-menu-button[t-message-status="sending"] {
312+
.t-theme-message[t-status="sending"] .t-message-action-menu-button,
313+
.t-theme-message[t-status="sending"] .t-add-reaction-button {
313314
visibility: hidden;
314315
}
315316

src/Message.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
/** @param {MessageProps} props */
1313
export function Message(props) {
1414
const { message, messageStatus, permissions, common } = props;
15-
const { currentUser, theme, chatbox, conversation, t } = common;
15+
const { currentUser, theme, chatbox, conversationId, t } = common;
1616
const { Avatar, Icon, ReferencedMessage, TimeAgo, MessageActionMenu } = theme;
1717

18-
const participants = useParticipants(conversation.id, 3);
18+
const participants = useParticipants(conversationId, 3);
1919

2020
const isGroupChat = participants.length >= 3;
2121
const sender = message.sender;
@@ -40,6 +40,7 @@ export function Message(props) {
4040
className="t-theme-message"
4141
t-sender=${senderType}
4242
t-message-id=${message.id}
43+
t-status=${messageStatus}
4344
>
4445
<div className="t-message-row">
4546
${sender &&
@@ -81,7 +82,6 @@ export function Message(props) {
8182
html`
8283
<${PopoverButton}
8384
type="menu"
84-
t-message-status=${messageStatus}
8585
popoverComponent=${MessageActionMenu}
8686
popoverProps=${{ message, permissions, common }}
8787
className="t-message-action-menu-button"
@@ -136,6 +136,10 @@ export function Message(props) {
136136
function StatusTick({ messageStatus, common }) {
137137
const { Icon } = common.theme;
138138

139+
if (messageStatus === "virtual") {
140+
return null;
141+
}
142+
139143
if (messageStatus === "sending") {
140144
return html`
141145
<span className="t-status-icon">

src/NoConversationSelected.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This component renders nothing by default. You can add styles here when you add markup to the component. */

src/NoConversationSelected.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @import { NoConversationSelectedProps } from "@talkjs/react-components"; */
2+
3+
/**
4+
* NoConversationSelected is rendered inside the chatbox panel when `conversationId` is
5+
* set to `null`. This happens e.g. when an Inbox is loaded without a selected
6+
* conversation.
7+
*
8+
* @param {NoConversationSelectedProps} props
9+
*/
10+
export function NoConversationSelected({ common }) {
11+
return null;
12+
}

src/TimeAgo.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ import { html, useTimeAgo } from "@talkjs/react-components";
22
/** @import { TimeAgoProps } from "@talkjs/react-components"; */
33

44
/** @param {TimeAgoProps} props */
5-
export function TimeAgo({ timestamp, common }) {
5+
export function TimeAgo(props) {
6+
if (props.timestamp === -1) {
7+
// virtual message, no timestamp
8+
return null;
9+
}
10+
return html`<${TimeAgoSpan} ...${props} />`;
11+
}
12+
13+
/** @param {TimeAgoProps} props */
14+
function TimeAgoSpan({ timestamp, common }) {
615
const { t } = common;
16+
717
// Turns `timestamp` into a long, informative, locale specific datetime string
818
const absoluteDateTimeString = new Date(timestamp).toLocaleString(t.locale, {
919
weekday: "short",

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@import url("MessageListFooter.css");
1111
@import url("BeforeMessages.css");
1212
@import url("AfterMessages.css");
13+
@import url("NoConversationSelected.css");
1314

1415
@import url("AudioBlock.css");
1516
@import url("FileBlock.css");

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export declare const MessageDivider = Theme["MessageDivider"];
1212
export declare const MessageListFooter = Theme["MessageListFooter"];
1313
export declare const BeforeMessages = Theme["BeforeMessages"];
1414
export declare const AfterMessages = Theme["AfterMessages"];
15+
export declare const NoConversationSelected = Theme["NoConversationSelected"];
1516
export declare const CompactMessageContent = Theme["CompactMessageContent"];
1617

1718
export declare const AudioBlock = Theme["AudioBlock"];

0 commit comments

Comments
 (0)