-
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.
Merge remote-tracking branch 'origin/chat'
- Loading branch information
Showing
10 changed files
with
360 additions
and
30 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
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,16 @@ | ||
import { useLocation } from 'react-router-dom'; | ||
import useUserContext from '../../../hooks/useUserContext'; | ||
|
||
const Message = ({ message, username }: { message: string; username: string }) => { | ||
const { user } = useUserContext(); | ||
const { pathname } = useLocation(); | ||
|
||
return ( | ||
<div className={`${username === user?.username ? 'chat-text-me' : 'chat-text-user'}`}> | ||
{pathname.includes('community') && <p className='user-name'>{username}</p>} | ||
<p className='message'>{message}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Message; |
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,19 @@ | ||
import React, { useRef, useState } from 'react'; | ||
import { addDoc, collection, serverTimestamp } from 'firebase/firestore'; | ||
import { auth, db } from '../../../firebaseConfig'; | ||
|
||
const SendMessage = async (message: string, sendTo: string) => { | ||
if (message.trim() === '') { | ||
alert('Enter valid message'); | ||
return; | ||
} | ||
const user = auth.currentUser; | ||
await addDoc(collection(db, 'messages'), { | ||
text: message, | ||
email: user, | ||
sendTo, | ||
createdAt: serverTimestamp(), | ||
}); | ||
// scroll?.current.scrollIntoView({ behavior: "smooth" }); | ||
}; | ||
export default SendMessage; |
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,127 @@ | ||
.chat-container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
min-height: 90vh; | ||
background-color: #FFFCF5; | ||
overflow-y: scroll; | ||
} | ||
|
||
.scrollable-container { | ||
width: 100%; | ||
height: 200px; | ||
overflow-y: scroll; | ||
} | ||
|
||
.ruled-paper { | ||
background-size: 100% 3em; | ||
background-color: #FFFCF5; | ||
flex-grow: 1; | ||
width: 100%; | ||
padding-top: 0.2rem; | ||
line-height: 1.2; | ||
} | ||
|
||
|
||
.carrot { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
padding: 20px; | ||
} | ||
|
||
.community-title { | ||
margin: 0 auto; /* Horizontally center */ | ||
background: #6D89B0; | ||
text-align: start; | ||
padding: 10px; | ||
border-radius: 5px; | ||
color: white; | ||
font-size: 24px; | ||
font-weight: bold; | ||
} | ||
|
||
.chat-title { | ||
padding: 20px; | ||
font-size: 24px; | ||
font-weight: bold; | ||
} | ||
|
||
.chat-header { | ||
background-color: #466694; | ||
color: #FFFFFF; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
} | ||
|
||
.chat-footer { | ||
background-color: #466694; | ||
color: #FFFFFF; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
} | ||
|
||
.chat-text-user, .chat-text-me { | ||
display: inline-block; | ||
font-size: 24px; | ||
max-width: 100%; | ||
white-space: nowrap; | ||
margin-bottom: 5px; | ||
} | ||
|
||
.chat-text-user { | ||
text-align: left !important; | ||
padding: 3px 15px; | ||
background: #f1f1f1; | ||
color: #000 !important; | ||
border-radius: 20px 20px 20px 3px; | ||
} | ||
|
||
.chat-text-me { | ||
float: right; | ||
padding: 3px 15px; | ||
background: #DFAEA1; | ||
color: #fff !important; | ||
border-radius: 30px 20px 3px 30px; | ||
margin-bottom: 10px; | ||
clear: both; | ||
} | ||
|
||
.username { | ||
background: #6D89B0; | ||
color: white; | ||
font-size: 24px; | ||
max-width: 975px; | ||
font-weight: bold; | ||
} | ||
|
||
.username::placeholder { | ||
color: white; | ||
} | ||
|
||
.message { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
.send { | ||
background: #BABDE2; | ||
border-radius: 10px; | ||
padding: 5px; | ||
color: white; | ||
margin-right: 20px; | ||
font-size: 24px; | ||
font-weight: bold; | ||
} | ||
|
||
.send:hover { | ||
background-color: #9498B5; | ||
} |
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,71 @@ | ||
import './index.css'; | ||
import { FaCaretUp, FaCaretDown } from 'react-icons/fa'; | ||
import { useLocation } from 'react-router-dom'; | ||
import Message from './Message'; | ||
import useChat from '../../../hooks/useChat'; | ||
|
||
const ChatPage = () => { | ||
const { pathname } = useLocation(); | ||
const { | ||
currentMessage, | ||
messages, | ||
send, | ||
handleSendTo, | ||
handleInputChange, | ||
scrollUp, | ||
saveMessagesToUserAccount, | ||
scrollDown, | ||
} = useChat(); | ||
|
||
return ( | ||
<div className='chat-container'> | ||
<div className='chat-header d-flex'> | ||
{pathname.includes('community') ? ( | ||
<span className='chat-title'> | ||
chatting now: <span className='community-title'>community</span> | ||
</span> | ||
) : ( | ||
<> | ||
<span className='chat-title'>chatting now: </span> | ||
<input | ||
className='username' | ||
id='searchBar' | ||
placeholder={'email'} | ||
type='text' | ||
onChange={handleSendTo} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
<div className='ruled-paper scrollable-container'> | ||
{messages.map((m, index) => ( | ||
<> | ||
<Message key={index} message={m.message} username={m.username} /> | ||
<br /> | ||
</> | ||
))} | ||
</div> | ||
<div className='chat-footer d-flex'> | ||
<div className='carrot p-2'> | ||
<FaCaretUp size={45} onClick={scrollUp} /> | ||
<FaCaretDown size={45} onClick={scrollDown} /> | ||
</div> | ||
<input | ||
className='p-2 message' | ||
id='searchBar' | ||
placeholder='type message here' | ||
type='text' | ||
value={currentMessage} | ||
onChange={handleInputChange} | ||
/> | ||
<button | ||
className='send p-2' | ||
onClick={() => saveMessagesToUserAccount(currentMessage, send)}> | ||
send | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ChatPage; |
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
Oops, something went wrong.