Skip to content

Commit a812742

Browse files
style: update the chat item
Co-authored-by: Yurii Kinakh <yuriikinakh5@gmail.com>
1 parent 5b1afb7 commit a812742

File tree

2 files changed

+12
-56
lines changed

2 files changed

+12
-56
lines changed

src/App.css

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@
252252
max-height: 100% !important;
253253
display: flex !important;
254254
flex-direction: column !important;
255-
gap: 8px !important;
255+
align-items: flex-start !important;
256+
gap: 6px !important;
256257
margin-top: auto !important;
257258
padding: 0 16px !important;
258259
pointer-events: auto !important;
@@ -265,37 +266,17 @@
265266
}
266267

267268
.vp-chat-message {
268-
display: flex !important;
269-
flex-direction: row !important;
270-
align-items: flex-start !important;
271-
gap: 8px !important;
272-
}
273-
274-
.vp-chat-avatar {
275-
width: 32px !important;
276-
height: 32px !important;
277-
flex-shrink: 0 !important;
278-
border-radius: 50% !important;
279-
object-fit: cover !important;
280-
}
281-
282-
.vp-chat-content {
283269
display: flex !important;
284270
flex-direction: column !important;
285-
gap: 2px !important;
286-
}
287-
288-
.vp-chat-username {
289-
color: rgba(255, 255, 255, 0.85) !important;
290-
font-size: 14px !important;
291-
line-height: 1 !important;
292-
font-weight: bold !important;
271+
padding: 4px 8px !important;
272+
background: rgba(255, 255, 255, 0.2) !important;
273+
border-radius: 4px !important;
293274
}
294275

295-
.vp-chat-text {
276+
.vp-chat-message-text {
296277
color: #ffffff !important;
297-
font-size: 16px !important;
298-
line-height: 1 !important;
278+
font-size: 15px !important;
279+
line-height: 1.2 !important;
299280
word-break: break-word !important;
300281
}
301282

src/components/RoomScreen.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,10 @@ function useChat() {
6262
const [messages, setMessages] = useState([]);
6363
const [message, setMessage] = useState('');
6464

65-
useEffect(() => {
66-
const handleData = (payload) => {
67-
try {
68-
const decoder = new TextDecoder();
69-
const json = JSON.parse(decoder.decode(payload));
70-
if (json.message) {
71-
setMessages((prev) => [...prev, json]);
72-
}
73-
} catch (e) {
74-
console.error('Failed to parse chat message', e);
75-
}
76-
};
77-
room.on(RoomEvent.DataReceived, handleData);
78-
return () => room.off(RoomEvent.DataReceived, handleData);
79-
}, [room]);
80-
8165
const sendMessage = useCallback(() => {
8266
const text = message.trim();
8367
if (!text) return;
84-
const msg = { username: USERNAME, avatar: 'default.jpg', message: text };
68+
const msg = { id: crypto.randomUUID(), username: USERNAME, message: text, time: Date.now() };
8569
try {
8670
const encoder = new TextEncoder();
8771
room.localParticipant.publishData(encoder.encode(JSON.stringify(msg)), { reliable: true });
@@ -289,18 +273,9 @@ function RoomContainer({ roomName, onLeave }) {
289273
{remoteParticipants.length > 0 && (
290274
<div className="vp-chat-overlay">
291275
<div className="vp-chat-messages">
292-
{messages.map((msg, i) => (
293-
<div key={i} className="vp-chat-message">
294-
<img
295-
src={AVATAR_URL + (msg.avatar || 'default.jpg')}
296-
alt={msg.username}
297-
className="vp-chat-avatar"
298-
crossOrigin="anonymous"
299-
/>
300-
<div className="vp-chat-content">
301-
<span className="vp-chat-username">{msg.username}</span>
302-
<span className="vp-chat-text">{msg.message}</span>
303-
</div>
276+
{messages.map((msg) => (
277+
<div key={msg.id} className="vp-chat-message">
278+
<span className="vp-chat-message-text">{msg.message}</span>
304279
</div>
305280
))}
306281
<div ref={messagesEndRef} />

0 commit comments

Comments
 (0)