Skip to content

Commit

Permalink
Pre Merge Push
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWaz28 committed Feb 4, 2022
1 parent 8f2fcb3 commit 5510310
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CreateProject from './components/Dashboard/CreateProject';
import AllProjects from './components/Dashboard/AllProjects';
import SingleProject from './components/Dashboard/SingleProject';
import MessagingPage from './components/Messaging/MessagingPage'
import SingleConversation from './components/Messaging/SingleConversation'

function App() {
const { authIsReady, user } = useAuthContext()
Expand Down Expand Up @@ -61,6 +62,10 @@ function App() {
<Route path="/messages">
<MessagingPage />
</Route>
<Route path="/conversations/:id">
{!user && <Redirect to="/login" />}
{user && <SingleConversation />}
</Route>
</Switch>
</BrowserRouter>
)}
Expand Down
11 changes: 6 additions & 5 deletions src/components/Messaging/AllMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Avatar from "../UI/Avatar"
export default function AllMessages ({ conversation }) {
const { user } = useAuthContext()
console.log('USER FROM useAuthContext: ', user)
console.log('THE CONVERSATION: ', conversation)
const { updateDocument, response } = useFirestore('conversations') //not sure what this does
const [newMessage, setNewMessage] = useState('')

Expand All @@ -34,23 +35,23 @@ export default function AllMessages ({ conversation }) {
<div className='MessagingPage'>
<h4> Conversation Messages </h4>
{conversation.messages.length > 0 && conversation.messages.map(msg => (
console.log(msg),
<div key={msg.id} className='singleMessage'>

<div className='message-sender-name'>
<p> From: {msg.senderName} </p>
</div>
<div className='message-content'>
<p> {msg.message} </p>
</div>
<div className='message-createdAt'>
<p> Sent At: {msg.createdAt} </p>
</div>

</div>
))}

<form className='new-message-form' onSubmit={handleSubmit}>
<input onChange={(e) => setNewMessage(e.target.value)} value={newMessage} placeholder="say something nice" />
<button type="submit">️SEND</button>
</form>
<button type="submit">️SEND</button>
</form>
</div>
)
}
23 changes: 23 additions & 0 deletions src/components/Messaging/SingleConversation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useParams } from "react-router-dom"
import { useDocument } from '../../hooks/useDocument'

import AllMessages from "./AllMessages"

export default function SingleConversation() {
const { id } = useParams()
const { document, error } = useDocument('conversations', id)

if (error) {
return <div className="error">{error}</div>
}
if (!document) {
return <div className="loading">Loading...</div>
}


return (
<div className="singleConversation">
<AllMessages conversation={document} />
</div>
)
}

0 comments on commit 5510310

Please sign in to comment.