Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#33 messages saving to firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
gkillick authored and martinsenecal committed Mar 29, 2022
1 parent 6a720ed commit cc4cdd3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/chat/chatroom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ function ChatRoom(props: PatientData) {

// creating message object
const message: Message = {
message: e.value,
message: formValue,
createdAt: Timestamp.now(),
ownerID: state.id,
};

// add message to messages array
console.log(message);
await chatRef.update({
// append message

messages: firebase.firestore.FieldValue.arrayUnion(message),
});

Expand Down Expand Up @@ -99,15 +101,15 @@ function Chat(props: PatientData) {
}

function ChatMessage(props: any) {
const { text, uid } = props.message;
const { message, ownerID } = props.message;
const user = React.useContext(UserContext);

const messageClass = uid === user.state.id ? 'sent' : 'received';
const messageClass = ownerID === user.state.id ? 'sent' : 'received';

return (
<div className={`message ${messageClass}`}>
<Avatar src={`https://avatars.dicebear.com/api/initials/${user.state.firstName}.svg`} alt="Avatar-Icon" />
<p>{text}</p>
<p>{message}</p>
</div>
);
}
Expand Down

0 comments on commit cc4cdd3

Please sign in to comment.