Skip to content

Commit 3810775

Browse files
committed
fix: blabsy format
1 parent ac993ac commit 3810775

File tree

10 files changed

+344
-175
lines changed

10 files changed

+344
-175
lines changed

platforms/blabsy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dev:emulators": "concurrently npm:dev npm:emulators",
99
"build": "next build",
1010
"start": "next start",
11-
"format": "prettier --check .",
11+
"format": "prettier --write .",
1212
"lint": "next lint",
1313
"test": "jest --watch",
1414
"test:ci": "jest --ci"

platforms/blabsy/src/components/chat/add-members.tsx

Lines changed: 160 additions & 91 deletions
Large diffs are not rendered by default.

platforms/blabsy/src/components/chat/chat-list.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export function ChatList(): JSX.Element {
6666
return (
6767
<div className='flex h-full flex-col gap-4'>
6868
<div className='flex flex-1 items-center justify-center'>
69-
<p className='text-gray-500 dark:text-gray-400'>No chats yet</p>
69+
<p className='text-gray-500 dark:text-gray-400'>
70+
No chats yet
71+
</p>
7072
</div>
7173
<button
7274
type='button'

platforms/blabsy/src/components/chat/chat-window.tsx

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,23 @@ function MessageItem({
3636
isOwnMessage ? 'justify-end' : 'justify-start'
3737
}`}
3838
>
39-
<div className={`flex max-w-[70%] ${isOwnMessage ? 'flex-col items-end' : 'flex-col items-start'} gap-1`}>
39+
<div
40+
className={`flex max-w-[70%] ${
41+
isOwnMessage ? 'flex-col items-end' : 'flex-col items-start'
42+
} gap-1`}
43+
>
4044
{/* User Avatar and Name - Above the message */}
4145
{!isOwnMessage && showUserInfo && (
4246
<div className='flex items-center gap-2 mb-1'>
4347
<div className='relative flex h-6 w-6 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'>
4448
{userData?.photoURL ? (
4549
<Image
4650
src={userData.photoURL}
47-
alt={userData.name || userData.username || 'User'}
51+
alt={
52+
userData.name ||
53+
userData.username ||
54+
'User'
55+
}
4856
width={24}
4957
height={24}
5058
className='object-cover'
@@ -58,7 +66,7 @@ function MessageItem({
5866
</span>
5967
</div>
6068
)}
61-
69+
6270
{/* Message Bubble */}
6371
<div
6472
className={`rounded-2xl px-4 py-2 ${
@@ -92,7 +100,9 @@ export function ChatWindow(): JSX.Element {
92100
const [messageText, setMessageText] = useState('');
93101
const messagesEndRef = useRef<HTMLDivElement>(null);
94102
const [otherUser, setOtherUser] = useState<User | null>(null);
95-
const [participantsData, setParticipantsData] = useState<Record<string, User>>({});
103+
const [participantsData, setParticipantsData] = useState<
104+
Record<string, User>
105+
>({});
96106
const [isLoading, setIsLoading] = useState(false);
97107
const [openMemberList, setOpenMemberList] = useState(false);
98108
const [openEditMenu, setOpenEditMenu] = useState<boolean>(false);
@@ -108,7 +118,7 @@ export function ChatWindow(): JSX.Element {
108118
const fetchParticipantsData = async (): Promise<void> => {
109119
try {
110120
const newParticipantsData: Record<string, User> = {};
111-
121+
112122
// Fetch data for all participants
113123
for (const participantId of currentChat.participants) {
114124
if (participantId === user?.id) {
@@ -118,19 +128,27 @@ export function ChatWindow(): JSX.Element {
118128
}
119129
} else {
120130
// Fetch other participants' data
121-
const userDoc = await getDoc(doc(db, 'users', participantId));
131+
const userDoc = await getDoc(
132+
doc(db, 'users', participantId)
133+
);
122134
if (userDoc.exists()) {
123-
newParticipantsData[participantId] = userDoc.data() as User;
135+
newParticipantsData[participantId] =
136+
userDoc.data() as User;
124137
}
125138
}
126139
}
127-
140+
128141
setParticipantsData(newParticipantsData);
129-
142+
130143
// Set otherUser for direct chats
131144
if (currentChat.type === 'direct') {
132-
const otherParticipant = currentChat.participants.find(p => p !== user?.id);
133-
if (otherParticipant && newParticipantsData[otherParticipant]) {
145+
const otherParticipant = currentChat.participants.find(
146+
(p) => p !== user?.id
147+
);
148+
if (
149+
otherParticipant &&
150+
newParticipantsData[otherParticipant]
151+
) {
134152
setOtherUser(newParticipantsData[otherParticipant]);
135153
}
136154
}
@@ -255,25 +273,44 @@ export function ChatWindow(): JSX.Element {
255273
{[...messages]
256274
.reverse()
257275
.map((message, index, reversedMessages) => {
258-
const isOwnMessage = message.senderId === user?.id;
259-
const nextMessage = reversedMessages[index + 1];
260-
const prevMessage = reversedMessages[index - 1];
261-
276+
const isOwnMessage =
277+
message.senderId === user?.id;
278+
const nextMessage =
279+
reversedMessages[index + 1];
280+
const prevMessage =
281+
reversedMessages[index - 1];
282+
262283
// Show time if next message is from different sender or doesn't exist
263-
const showTime = !nextMessage || nextMessage.senderId !== message.senderId;
264-
284+
const showTime =
285+
!nextMessage ||
286+
nextMessage.senderId !==
287+
message.senderId;
288+
265289
// Show user info if:
266290
// 1. It's a group chat AND
267291
// 2. Previous message is from different sender OR doesn't exist OR
268292
// 3. Previous message is from same sender but more than 5 minutes ago
269-
const showUserInfo = currentChat?.type === 'group' && !isOwnMessage && (
270-
!prevMessage ||
271-
prevMessage.senderId !== message.senderId ||
272-
(prevMessage.createdAt?.toDate && message.createdAt?.toDate &&
273-
Math.abs(prevMessage.createdAt.toDate().getTime() - message.createdAt.toDate().getTime()) > 5 * 60 * 1000)
274-
);
275-
276-
const userData = participantsData[message.senderId];
293+
const showUserInfo =
294+
currentChat?.type === 'group' &&
295+
!isOwnMessage &&
296+
(!prevMessage ||
297+
prevMessage.senderId !==
298+
message.senderId ||
299+
(prevMessage.createdAt
300+
?.toDate &&
301+
message.createdAt?.toDate &&
302+
Math.abs(
303+
prevMessage.createdAt
304+
.toDate()
305+
.getTime() -
306+
message.createdAt
307+
.toDate()
308+
.getTime()
309+
) >
310+
5 * 60 * 1000));
311+
312+
const userData =
313+
participantsData[message.senderId];
277314

278315
return (
279316
<MessageItem

0 commit comments

Comments
 (0)