Skip to content

Commit

Permalink
final components
Browse files Browse the repository at this point in the history
  • Loading branch information
ghassenbenzahra123 committed Feb 9, 2022
1 parent 68147df commit d4f6a3e
Show file tree
Hide file tree
Showing 16 changed files with 715 additions and 73 deletions.
12 changes: 6 additions & 6 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -1696,11 +1696,11 @@ div.rta__autocomplete.str-chat__emojisearch {
outline: none;
}

.team-channerl-header_menu-icon {
.team-channel-header_menu-icon {
display: none;
}

.channerl-list__container-toggle {
.channel-list__container-toggle {
display: none;
height: 50px;
width: 50px;
Expand Down Expand Up @@ -1733,7 +1733,7 @@ div.rta__autocomplete.str-chat__emojisearch {
display: none;
}

.team-channerl-header_menu-icon {
.team-channel-header_menu-icon {
display: flex;
}

Expand Down Expand Up @@ -1771,7 +1771,7 @@ div.rta__autocomplete.str-chat__emojisearch {
width: 100%;
}

.channerl-list__container-toggle {
.channel-list__container-toggle {
display: flex;
}

Expand All @@ -1796,7 +1796,7 @@ div.rta__autocomplete.str-chat__emojisearch {
}

@media screen and (max-width: 650px) {
.channerl-list__container-toggle {
.channel-list__container-toggle {
right: -3%;
}
}
Expand All @@ -1806,7 +1806,7 @@ div.rta__autocomplete.str-chat__emojisearch {
width: 150px;
}

.channerl-list__container-toggle {
.channel-list__container-toggle {
right: -5%;
}
}
Expand Down
46 changes: 41 additions & 5 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import React from 'react';
import React, { useState } from 'react';
import { StreamChat } from 'stream-chat';
import { Chat } from 'stream-chat-react';
import Cookies from 'universal-cookie';
import { ChannelListContainer, ChannelContainer, Auth } from './components';
import './App.css'

import 'stream-chat-react/dist/css/index.css';
import './App.css';

const cookies = new Cookies();

const apiKey = '8sxnm6cqgmtd';

const authToken = cookies.get("token");
const client = StreamChat.getInstance(apiKey);
const authToken = false;


if (authToken) {
client.connectUser({
id: cookies.get('userId'),
name: cookies.get('username'),
fullName: cookies.get('fullName'),
image: cookies.get('avatarURL'),
hashedPassword: cookies.get('hashedPassword'),
phoneNumber: cookies.get('phoneNumber'),
}, authToken)
}


function App() {

const [createType, setCreateType] = useState('');
const [isCreating, setIsCreating] = useState(false);
const [isEditing, setIsEditing] = useState(false);


if (!authToken) return <Auth />
return <div className="app__wrapper">
<Chat client={client} theme="team light">
<ChannelListContainer />
<ChannelContainer />
<ChannelListContainer
isCreating={isCreating}
setIsCreating={setIsCreating}
setCreateType={setCreateType}
setIsEditing={setIsEditing}
/>
<ChannelContainer
isCreating={isCreating}
setIsCreating={setIsCreating}
isEditing={isEditing}
setIsEditing={setIsEditing}
createType={createType} />
</Chat>
</div>;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Auth = () => {

const { username, password, phoneNumber, avatarURL } = form;

const URL = 'https://localhost:5000/auth';
const URL = 'http://localhost:5000/auth';
// const URL = 'https://medical-pager.herokuapp.com/auth';

const { data: { token, userId, hashedPassword, fullName } } = await axios.post(`${URL}/${isSignup ? 'signup' : 'login'}`, {
Expand Down
39 changes: 36 additions & 3 deletions client/src/components/ChannelContainer.jsx
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;
94 changes: 94 additions & 0 deletions client/src/components/ChannelInner.jsx
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;
Loading

0 comments on commit d4f6a3e

Please sign in to comment.