| ); | ); | ||||
| }; | }; | ||||
| const onSendMessageToGroupHandler = async () => { | |||||
| const onSendMessageToGroupHandler = async (e) => { | |||||
| e.preventDefault(); | |||||
| const userToFetch = connections.filter( | const userToFetch = connections.filter( | ||||
| (conn) => conn.userId === user.id && conn.roomId === activeRoom.id | (conn) => conn.userId === user.id && conn.roomId === activeRoom.id | ||||
| ); | ); | ||||
| <div className="messages p-3 border d-flex flex-column-reverse"> | <div className="messages p-3 border d-flex flex-column-reverse"> | ||||
| {/* mapirane poruke */} | {/* mapirane poruke */} | ||||
| {user && messages | |||||
| .map((n, index) => ( | |||||
| <div | |||||
| key={index} | |||||
| className={ | |||||
| n.isAccessMessage === true ? | |||||
| "d-flex flex-column align-items-center" : | |||||
| (n.senderId === user.id | |||||
| ? "d-flex flex-column align-items-end" | |||||
| : "d-flex flex-column align-items-start") | |||||
| } | |||||
| > | |||||
| {console.log("Message",n,"User id",user.id)} | |||||
| <p | |||||
| className={`p-2 px-4 mb-0 rounded message ${ | |||||
| n.senderId !== user.id | |||||
| ? "bg-primary text-light" | |||||
| : "bg-light text-dark" | |||||
| }`} | |||||
| {user && | |||||
| messages | |||||
| .map((n, index) => ( | |||||
| <div | |||||
| key={index} | |||||
| className={ | |||||
| n.isAccessMessage === true | |||||
| ? "d-flex flex-column align-items-center" | |||||
| : n.senderId === user.id | |||||
| ? "d-flex flex-column align-items-end" | |||||
| : "d-flex flex-column align-items-start" | |||||
| } | |||||
| > | > | ||||
| {n.content} | |||||
| </p> | |||||
| <p className="text-muted small m-0 p-0 mb-4"> | |||||
| {n.senderId !== user?.id ? ( | |||||
| activeUsers.some((m) => m === n.senderId) ? ( | |||||
| <BsCircleFill className="me-2 text-success" /> | |||||
| {console.log("Message", n, "User id", user.id)} | |||||
| <p | |||||
| className={`p-2 px-4 mb-0 rounded message ${ | |||||
| n.senderId !== user.id | |||||
| ? "bg-primary text-light" | |||||
| : "bg-light text-dark" | |||||
| }`} | |||||
| > | |||||
| {n.content} | |||||
| </p> | |||||
| <p className="text-muted small m-0 p-0 mb-4"> | |||||
| {n.senderId !== user?.id ? ( | |||||
| activeUsers.some((m) => m === n.senderId) ? ( | |||||
| <BsCircleFill className="me-2 text-success" /> | |||||
| ) : ( | |||||
| <BsCircleFill className="me-2 text-danger" /> | |||||
| ) | |||||
| ) : ( | ) : ( | ||||
| <BsCircleFill className="me-2 text-danger" /> | |||||
| ) | |||||
| ) : ( | |||||
| "" | |||||
| )} | |||||
| {n.isAccessMessage !== true && n.username} | |||||
| </p> | |||||
| </div> | |||||
| )) | |||||
| .reverse()} | |||||
| "" | |||||
| )} | |||||
| {n.isAccessMessage !== true && n.username} | |||||
| </p> | |||||
| </div> | |||||
| )) | |||||
| .reverse()} | |||||
| <div ref={messagesEndRef} /> | <div ref={messagesEndRef} /> | ||||
| </div> | </div> | ||||
| <Form | <Form | ||||
| style={{ height: "80px" }} | style={{ height: "80px" }} | ||||
| className="d-flex align-items-center" | className="d-flex align-items-center" | ||||
| onSubmit={onSendMessageToGroupHandler} | |||||
| > | > | ||||
| <InputGroup className="mb-3"> | <InputGroup className="mb-3"> | ||||
| <FormControl | <FormControl | ||||
| aria-label="Enter your messagge..." | aria-label="Enter your messagge..." | ||||
| aria-describedby="basic-addon2" | aria-describedby="basic-addon2" | ||||
| onChange={(e) => messageOnChangeHandler(e)} | onChange={(e) => messageOnChangeHandler(e)} | ||||
| value={message} | |||||
| /> | /> | ||||
| <Button | <Button | ||||
| className="px-5" | className="px-5" | ||||
| variant="outline-secondary" | variant="outline-secondary" | ||||
| id="button-addon2" | id="button-addon2" | ||||
| onClick={onSendMessageToGroupHandler} | |||||
| type="submit" | |||||
| > | > | ||||
| Send | Send | ||||
| </Button> | </Button> |