Fixed reload bug when clicking on a user

This commit is contained in:
Alois 2026-03-27 12:21:12 +01:00
commit 00659c4001
3 changed files with 34 additions and 5 deletions

View file

@ -51,10 +51,14 @@ export default function Screen(props: { children: React.ReactNode }) {
useEffect(() => {
let active = true;
const shouldBlockRender = userId === undefined || userId === 0;
if (shouldBlockRender) {
setLoading(true);
}
setError("");
setErrorDescription("");
setHasContinued(false);
void load("user_id").then(async (id) => {
if (!active) {
@ -64,7 +68,9 @@ export default function Screen(props: { children: React.ReactNode }) {
setUserId(id);
if (id === 0) {
if (shouldBlockRender) {
setLoading(false);
}
return;
}
@ -134,7 +140,9 @@ export default function Screen(props: { children: React.ReactNode }) {
acceptTOS(false);
}
if (shouldBlockRender) {
setLoading(false);
}
});
return () => {

View file

@ -41,6 +41,17 @@ export default function InputComponent() {
const time = Date.now();
const currentValue = value;
const currentUserId = userId();
const currentSharedSecret = sharedSecret();
if (!Number.isSafeInteger(currentUserId) || currentUserId <= 0) {
toast("error", "No conversation selected");
return;
}
if (!currentSharedSecret) {
toast("error", "Conversation key not ready yet");
return;
}
addLiveMessage({
height: 0,
@ -50,7 +61,7 @@ export default function InputComponent() {
sent_by_self: true,
});
const encryptedContext = await encrypt(sharedSecret(), currentValue);
const encryptedContext = await encrypt(currentSharedSecret, currentValue);
send("message_send", {
height: 0,

View file

@ -26,11 +26,13 @@ export default function Screen() {
} | null>(null);
const chatUserId = userId();
const hasValidChatUser = Number.isSafeInteger(chatUserId) && chatUserId > 0;
const messagesQuery = useInfiniteQuery({
queryKey: ["chat-messages", String(chatUserId)],
initialPageParam: 0,
queryFn: ({ pageParam }) => getMessages(PAGE_SIZE, Number(pageParam)),
enabled: hasValidChatUser,
getNextPageParam: (lastPage, allPages) => {
if (lastPage.length < PAGE_SIZE) {
return undefined;
@ -175,6 +177,14 @@ export default function Screen() {
void onScroll();
}, [onScroll]);
if (!hasValidChatUser) {
return (
<div className="w-full h-full flex items-center justify-center text-sm text-muted-foreground">
Select a conversation to start chatting.
</div>
);
}
return (
<div className="w-full h-full flex flex-col overflow-hidden px-2">
<div