diff --git a/app/chat/page.tsx b/app/chat/page.tsx index 51fdff1..9fc1b01 100644 --- a/app/chat/page.tsx +++ b/app/chat/page.tsx @@ -93,9 +93,13 @@ export default function ChatPage() { const [currentUser, setCurrentUser] = useState(null); const [isLoadingMessages, setIsLoadingMessages] = useState(false); const [isLoadingMore, setIsLoadingMore] = useState(false); - const [hasMoreMessages, setHasMoreMessages] = useState>({}); + const [hasMoreMessages, setHasMoreMessages] = useState< + Record + >({}); const [offsets, setOffsets] = useState>({}); - const [messagesByChat, setMessagesByChat] = useState>({}); + const [messagesByChat, setMessagesByChat] = useState< + Record + >({}); const [chats, setChats] = useState([]); const scrollContainerRef = useRef(null); @@ -134,7 +138,7 @@ export default function ChatPage() { status: "read", }; }, - [currentUser] + [currentUser], ); /* ---------------- Fetch Historical Messages ---------------- */ @@ -151,7 +155,7 @@ export default function ChatPage() { try { const res = await fetch( - `/api/messages?room_id=${roomId}&limit=${limit}&offset=${currentOffset}` + `/api/messages?room_id=${roomId}&limit=${limit}&offset=${currentOffset}`, ); const data = await res.json(); if (data.error) throw new Error(data.error); @@ -167,8 +171,8 @@ export default function ChatPage() { : newMessages; const unique = combined.filter( - (msg, index, self) => - index === self.findIndex((m) => m.id === msg.id) + (msg: ChatMessage, index: number, self: ChatMessage[]) => + index === self.findIndex((m: ChatMessage) => m.id === msg.id), ); return { ...prev, [roomId]: unique }; @@ -202,7 +206,7 @@ export default function ChatPage() { setIsLoadingMore(false); } }, - [offsets, isLoadingMessages, isLoadingMore, transformToChatMessage] + [offsets, isLoadingMessages, isLoadingMore, transformToChatMessage], ); /* ---------------- Auto Scroll ---------------- */ @@ -241,8 +245,7 @@ export default function ChatPage() { setReputationScore(calculateReputation(currentPublicKey)); updateScore(); window.addEventListener("reputationUpdate", updateScore); - return () => - window.removeEventListener("reputationUpdate", updateScore); + return () => window.removeEventListener("reputationUpdate", updateScore); }, [currentPublicKey]); /* ---------------- Select Chat ---------------- */ @@ -283,24 +286,19 @@ export default function ChatPage() { }; const selectedChat = selectedChatId - ? chats.find((c) => c.id === selectedChatId) ?? null + ? (chats.find((c) => c.id === selectedChatId) ?? null) : null; - const messages = selectedChat - ? messagesByChat[selectedChat.id] ?? [] - : []; + const messages = selectedChat ? (messagesByChat[selectedChat.id] ?? []) : []; return (
- {/* Sidebar */}