-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68147df
commit d4f6a3e
Showing
16 changed files
with
715 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
import React from 'react'; | ||
import { Channel, MessageTeam } from 'stream-chat-react'; | ||
|
||
const ChannelContainer = () => { | ||
return ( | ||
<h>Channel Container</h> | ||
import { ChannelInner, CreateChannel, EditChannel } from '.'; | ||
const ChannelContainer = ({ isCreating, setIsCreating, isEditing, setIsEditing, createType }) => { | ||
|
||
if (isCreating) { | ||
return ( | ||
<div className="channel__container"> | ||
<CreateChannel createType={createType} setIsCreating={setIsCreating} /> | ||
</div> | ||
) | ||
} | ||
|
||
if (isEditing) { | ||
return ( | ||
<div className="channel__container"> | ||
<EditChannel setIsEditing={setIsEditing} /> | ||
</div> | ||
) | ||
} | ||
|
||
const EmptyState = () => ( | ||
<div className="channel-empty__container"> | ||
<p className="channel-empty__first">This is the beginning of your chat history.</p> | ||
<p className="channel-empty__second">Send messages, attachments, links, emojis, and more!</p> | ||
</div> | ||
) | ||
|
||
return ( | ||
<div className=" channel__container"> | ||
<Channel | ||
EmptyStateIndicator={EmptyState} | ||
Message={(messageProps, i) => <MessageTeam key={i} {...messageProps} />} | ||
> | ||
<ChannelInner setIsEditing={setIsEditing} /> | ||
</Channel> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChannelContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React, { useState } from 'react'; | ||
import { MessageList, MessageInput, Thread, Window, useChannelActionContext, Avatar, useChannelStateContext, useChatContext } from 'stream-chat-react'; | ||
|
||
import { ChannelInfo } from '../assets'; | ||
|
||
export const GiphyContext = React.createContext({}); | ||
|
||
const ChannelInner = ({ setIsEditing }) => { | ||
const [giphyState, setGiphyState] = useState(false); | ||
const { sendMessage } = useChannelActionContext(); | ||
|
||
const overrideSubmitHandler = (message) => { | ||
let updatedMessage = { | ||
attachments: message.attachments, | ||
mentioned_users: message.mentioned_users, | ||
parent_id: message.parent?.id, | ||
parent: message.parent, | ||
text: message.text, | ||
}; | ||
|
||
if (giphyState) { | ||
updatedMessage = { ...updatedMessage, text: `/giphy ${message.text}` }; | ||
} | ||
|
||
if (sendMessage) { | ||
sendMessage(updatedMessage); | ||
setGiphyState(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<GiphyContext.Provider value={{ giphyState, setGiphyState }}> | ||
<div style={{ display: 'flex', width: '100%' }}> | ||
<Window> | ||
<TeamChannelHeader setIsEditing={setIsEditing} /> | ||
<MessageList /> | ||
<MessageInput overrideSubmitHandler={overrideSubmitHandler} /> | ||
</Window> | ||
<Thread /> | ||
</div> | ||
</GiphyContext.Provider> | ||
); | ||
}; | ||
|
||
const TeamChannelHeader = ({ setIsEditing }) => { | ||
const { channel, watcher_count } = useChannelStateContext(); | ||
const { client } = useChatContext(); | ||
|
||
const MessagingHeader = () => { | ||
const members = Object.values(channel.state.members).filter(({ user }) => user.id !== client.userID); | ||
const additionalMembers = members.length - 3; | ||
|
||
if (channel.type === 'messaging') { | ||
return ( | ||
<div className='team-channel-header__name-wrapper'> | ||
{members.map(({ user }, i) => ( | ||
<div key={i} className='team-channel-header__name-multi'> | ||
<Avatar image={user.image} name={user.fullName || user.id} size={32} /> | ||
<p className='team-channel-header__name user'>{user.fullName || user.id}</p> | ||
</div> | ||
))} | ||
|
||
{additionalMembers > 0 && <p className='team-channel-header__name user'>and {additionalMembers} more</p>} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className='team-channel-header__channel-wrapper'> | ||
<p className='team-channel-header__name'># {channel.data.name}</p> | ||
<span style={{ display: 'flex' }} onClick={() => setIsEditing(true)}> | ||
<ChannelInfo /> | ||
</span> | ||
</div> | ||
); | ||
}; | ||
|
||
const getWatcherText = (watchers) => { | ||
if (!watchers) return 'No users online'; | ||
if (watchers === 1) return '1 user online'; | ||
return `${watchers} users online`; | ||
}; | ||
|
||
return ( | ||
<div className='team-channel-header__container'> | ||
<MessagingHeader /> | ||
<div className='team-channel-header__right'> | ||
<p className='team-channel-header__right-text'>{getWatcherText(watcher_count)}</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChannelInner; |
Oops, something went wrong.