Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, {
useEffect,
useMemo,

Check warning on line 5 in app/chat/page.tsx

View workflow job for this annotation

GitHub Actions / Check & Build

'useMemo' is defined but never used. Allowed unused vars must match /^_/u
useState,
useCallback,
useRef,
Expand Down Expand Up @@ -93,9 +93,13 @@
const [currentUser, setCurrentUser] = useState<any>(null);
const [isLoadingMessages, setIsLoadingMessages] = useState(false);
const [isLoadingMore, setIsLoadingMore] = useState(false);
const [hasMoreMessages, setHasMoreMessages] = useState<Record<string, boolean>>({});
const [hasMoreMessages, setHasMoreMessages] = useState<
Record<string, boolean>
>({});
const [offsets, setOffsets] = useState<Record<string, number>>({});
const [messagesByChat, setMessagesByChat] = useState<Record<string, ChatMessage[]>>({});
const [messagesByChat, setMessagesByChat] = useState<
Record<string, ChatMessage[]>
>({});
const [chats, setChats] = useState<ChatPreview[]>([]);

const scrollContainerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -134,7 +138,7 @@
status: "read",
};
},
[currentUser]
[currentUser],
);

/* ---------------- Fetch Historical Messages ---------------- */
Expand All @@ -151,7 +155,7 @@

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);
Expand All @@ -167,8 +171,8 @@
: 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 };
Expand Down Expand Up @@ -202,7 +206,7 @@
setIsLoadingMore(false);
}
},
[offsets, isLoadingMessages, isLoadingMore, transformToChatMessage]
[offsets, isLoadingMessages, isLoadingMore, transformToChatMessage],
);

/* ---------------- Auto Scroll ---------------- */
Expand Down Expand Up @@ -241,8 +245,7 @@
setReputationScore(calculateReputation(currentPublicKey));
updateScore();
window.addEventListener("reputationUpdate", updateScore);
return () =>
window.removeEventListener("reputationUpdate", updateScore);
return () => window.removeEventListener("reputationUpdate", updateScore);
}, [currentPublicKey]);

/* ---------------- Select Chat ---------------- */
Expand Down Expand Up @@ -283,24 +286,19 @@
};

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 (
<div className="min-h-screen bg-background flex flex-col">
<Header />
<main className="flex-1 flex justify-center pt-24 pb-8">
<div className="w-full max-w-6xl h-[min(82vh,760px)] bg-card border rounded-2xl shadow-lg flex overflow-hidden">

{/* Sidebar */}
<aside className="w-[340px] border-r flex flex-col">
<div className="p-4 font-semibold text-sm border-b">
Messages
</div>
<div className="p-4 font-semibold text-sm border-b">Messages</div>
<div className="flex-1 overflow-y-auto">
{chats.map((chat) => (
<button
Expand Down Expand Up @@ -335,7 +333,7 @@
"max-w-[70%] px-4 py-2 rounded-xl text-sm",
message.author === "me"
? "ml-auto bg-primary/10"
: "bg-card border"
: "bg-card border",
)}
>
{message.text}
Expand Down Expand Up @@ -365,4 +363,4 @@
<Footer />
</div>
);
}
}
4 changes: 2 additions & 2 deletions app/stellar-wallet-kit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
FREIGHTER_ID,
StellarWalletsKit,
RabetNetwork,
WalletNetwork,
FreighterModule,
AlbedoModule,
RabetModule,
Expand Down Expand Up @@ -44,7 +44,7 @@ function getKit(): StellarWalletsKit | null {
new LobstrModule(),
new HanaModule(),
],
network: RabetNetwork.PUBLIC,
network: WalletNetwork.PUBLIC,
selectedWalletId: getSelectedWalletId() ?? FREIGHTER_ID,
});
} catch (e) {
Expand Down
Loading
Loading