Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

d #69

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/ConversationsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class ConversationsApp extends React.Component {

getToken = () => {
// Paste your unique Chat token function
const myToken = "<Your token here>";
const myToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTSzZkNWFkM2Q1ZTgzOGNiZjNlNTc2MWFjYTkyYjM2ZjJmLTE2OTY0MDI2OTMiLCJncmFudHMiOnsiaWRlbnRpdHkiOiJuaWtpdGFAc3R1ZGVudHdpc2UuaW8iLCJjaGF0Ijp7InNlcnZpY2Vfc2lkIjoiSVMyMDM5YmQxMGNiYjU0NWMxYWVhMjkwNjNjYTU0NWI5NCJ9fSwiaWF0IjoxNjk2NDAyNjkzLCJleHAiOjE2OTY0MDYyOTMsImlzcyI6IlNLNmQ1YWQzZDVlODM4Y2JmM2U1NzYxYWNhOTJiMzZmMmYiLCJzdWIiOiJBQ2NhNmZkZmFhMjgzZDNiZTJiMThiMmI0MGYzZmY4NmNmIn0.pUiX3CqGpyhF_5uj3RWbuNrTL-EDMQgWW4orjqR70rs";
this.setState({ token: myToken }, this.initConversations);
};

Expand Down Expand Up @@ -109,11 +110,15 @@ class ConversationsApp extends React.Component {
});
});
this.conversationsClient.on("conversationJoined", (conversation) => {
this.setState({ conversations: [...this.state.conversations, conversation] });
this.setState({
conversations: [...this.state.conversations, conversation]
});
});
this.conversationsClient.on("conversationLeft", (thisConversation) => {
this.setState({
conversations: [...this.state.conversations.filter((it) => it !== thisConversation)]
conversations: [
...this.state.conversations.filter((it) => it !== thisConversation)
]
});
});
};
Expand All @@ -124,6 +129,9 @@ class ConversationsApp extends React.Component {
(it) => it.sid === selectedConversationSid
);

console.log(conversations);
console.log(selectedConversationSid);

let conversationContent;
if (selectedConversation) {
conversationContent = (
Expand Down Expand Up @@ -166,7 +174,8 @@ class ConversationsApp extends React.Component {
<HeaderItem>
<Text strong style={{ color: "white" }}>
{selectedConversation &&
(selectedConversation.friendlyName || selectedConversation.sid)}
(selectedConversation.friendlyName ||
selectedConversation.sid)}
</Text>
</HeaderItem>
<HeaderItem style={{ float: "right", marginLeft: "auto" }}>
Expand Down
74 changes: 39 additions & 35 deletions src/ConversationsList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React from "react";
import { List, Typography } from "antd";

import conversationsListStyles from "./assets/ConversationsList.module.css";
Expand All @@ -9,39 +9,43 @@ import { joinClassNames } from "./utils/class-name";
const { Text } = Typography;

export class ConversationsList extends React.Component {
render() {
const { conversations, selectedConversationSid, onConversationClick } = this.props;
render() {
const {
conversations,
selectedConversationSid,
onConversationClick
} = this.props;
console.log(conversations);
return (
<List
header={"Open Conversations"}
className={conversationsListStyles["conversations-list"]}
bordered={true}
dataSource={conversations}
renderItem={(item) => {
const activeChannel = item.sid === selectedConversationSid;
const conversationItemClassName = joinClassNames([
conversationsItemStyles["conversation-item"],
activeChannel &&
conversationsItemStyles["conversation-item--active"]
]);

return (
<List
header={"Open Conversations"}
className={conversationsListStyles['conversations-list']}
bordered={true}
loading={conversations.length === 0}
dataSource={conversations}
renderItem={item => {
const activeChannel = item.sid === selectedConversationSid;
const conversationItemClassName = joinClassNames([
conversationsItemStyles['conversation-item'],
activeChannel && conversationsItemStyles['conversation-item--active']
]);

return (
<List.Item
key={item.sid}
onClick={() => onConversationClick(item)}
className={conversationItemClassName}
>
<Text
strong
className={conversationsItemStyles['conversation-item-text']}
>
{item.friendlyName || item.sid}
</Text>
</List.Item>
)
}}
/>
)
}
return (
<List.Item
key={item.sid}
onClick={() => onConversationClick(item)}
className={conversationItemClassName}
>
<Text
strong
className={conversationsItemStyles["conversation-item-text"]}
>
{item.friendlyName || item.sid}
</Text>
</List.Item>
);
}}
/>
);
}
}