|
1 | 1 | import { useEffect, useRef, useState } from 'react'; |
2 | 2 | import { useChat } from '@lib/context/chat-context'; |
3 | 3 | import { useAuth } from '@lib/context/auth-context'; |
| 4 | +import { useWindow } from '@lib/context/window-context'; |
4 | 5 | import { formatDistanceToNow, set } from 'date-fns'; |
5 | 6 | import type { Message } from '@lib/types/message'; |
6 | 7 | import { getChatType } from '@lib/types/chat'; |
7 | 8 | import { |
8 | 9 | UserIcon, |
9 | 10 | PaperAirplaneIcon, |
10 | | - Cog6ToothIcon |
| 11 | + Cog6ToothIcon, |
| 12 | + ArrowLeftIcon |
11 | 13 | } from '@heroicons/react/24/outline'; |
12 | 14 | import Image from 'next/image'; |
13 | 15 | import { doc, getDoc } from 'firebase/firestore'; |
@@ -140,9 +142,10 @@ function MessageItem({ |
140 | 142 | } |
141 | 143 |
|
142 | 144 | export function ChatWindow(): JSX.Element { |
143 | | - const { currentChat, messages, sendNewMessage, markAsRead, loading } = |
| 145 | + const { currentChat, messages, sendNewMessage, markAsRead, loading, setCurrentChat } = |
144 | 146 | useChat(); |
145 | 147 | const { user } = useAuth(); |
| 148 | + const { isMobile } = useWindow(); |
146 | 149 | const [messageText, setMessageText] = useState(''); |
147 | 150 | const messagesEndRef = useRef<HTMLDivElement>(null); |
148 | 151 | const [otherUser, setOtherUser] = useState<User | null>(null); |
@@ -269,6 +272,15 @@ export function ChatWindow(): JSX.Element { |
269 | 272 | <> |
270 | 273 | <div className='flex h-fit items-center justify-between gap-3 border-b border-gray-200 p-4 dark:border-gray-800'> |
271 | 274 | <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 | + )} |
272 | 284 | <div className='relative flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700'> |
273 | 285 | {currentChat.type === 'group' ? ( |
274 | 286 | currentChat.photoURL ? ( |
|
0 commit comments