Skip to content

Commit 6c27f9c

Browse files
authored
style: fix blabsy mobile UI (#434)
1 parent 9221926 commit 6c27f9c

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { useEffect, useRef, useState } from 'react';
22
import { useChat } from '@lib/context/chat-context';
33
import { useAuth } from '@lib/context/auth-context';
4+
import { useWindow } from '@lib/context/window-context';
45
import { formatDistanceToNow, set } from 'date-fns';
56
import type { Message } from '@lib/types/message';
67
import { getChatType } from '@lib/types/chat';
78
import {
89
UserIcon,
910
PaperAirplaneIcon,
10-
Cog6ToothIcon
11+
Cog6ToothIcon,
12+
ArrowLeftIcon
1113
} from '@heroicons/react/24/outline';
1214
import Image from 'next/image';
1315
import { doc, getDoc } from 'firebase/firestore';
@@ -140,9 +142,10 @@ function MessageItem({
140142
}
141143

142144
export function ChatWindow(): JSX.Element {
143-
const { currentChat, messages, sendNewMessage, markAsRead, loading } =
145+
const { currentChat, messages, sendNewMessage, markAsRead, loading, setCurrentChat } =
144146
useChat();
145147
const { user } = useAuth();
148+
const { isMobile } = useWindow();
146149
const [messageText, setMessageText] = useState('');
147150
const messagesEndRef = useRef<HTMLDivElement>(null);
148151
const [otherUser, setOtherUser] = useState<User | null>(null);
@@ -269,6 +272,15 @@ export function ChatWindow(): JSX.Element {
269272
<>
270273
<div className='flex h-fit items-center justify-between gap-3 border-b border-gray-200 p-4 dark:border-gray-800'>
271274
<div className='flex items-center gap-3'>
275+
{isMobile && (
276+
<button
277+
type='button'
278+
onClick={() => setCurrentChat(null)}
279+
className='flex items-center justify-center rounded-full p-2 transition-colors hover:bg-gray-100 dark:hover:bg-gray-800'
280+
>
281+
<ArrowLeftIcon className='h-5 w-5' />
282+
</button>
283+
)}
272284
<div className='relative flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'>
273285
{currentChat.type === 'group' ? (
274286
currentChat.photoURL ? (

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
import { useWindow } from '@lib/context/window-context';
2+
import { useChat } from '@lib/context/chat-context';
13
import { ChatList } from './chat-list';
24
import { ChatWindow } from './chat-window';
35

46
export function Chat(): JSX.Element {
7+
const { isMobile } = useWindow();
8+
const { currentChat } = useChat();
9+
10+
// On mobile, show only chat list or chat window based on selection
11+
if (isMobile) {
12+
return (
13+
<main className='min-h-full w-full max-w-5xl pt-8 pb-8'>
14+
{currentChat ? (
15+
<div className='h-[calc(100vh-6rem)] rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black'>
16+
<ChatWindow />
17+
</div>
18+
) : (
19+
<div className='h-[calc(100vh-6rem)] rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black flex flex-col'>
20+
<ChatList />
21+
</div>
22+
)}
23+
</main>
24+
);
25+
}
26+
27+
// On desktop, show both in grid layout
528
return (
629
<main className='min-h-full w-full max-w-5xl pt-8'>
730
<div className='grid h-[calc(100vh-4rem)] grid-cols-1 gap-4 md:grid-cols-[350px_1fr]'>
8-
<div className='h-full rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black flex flex-col'>
31+
<div className='h-[calc(100vh-4rem)] rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black flex flex-col'>
932
<ChatList />
1033
</div>
1134
<div className='h-[calc(100vh-4rem)] rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-black'>

0 commit comments

Comments
 (0)