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

View file

@ -41,6 +41,17 @@ export default function InputComponent() {
const time = Date.now(); const time = Date.now();
const currentValue = value; const currentValue = value;
const currentUserId = userId(); 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({ addLiveMessage({
height: 0, height: 0,
@ -50,7 +61,7 @@ export default function InputComponent() {
sent_by_self: true, sent_by_self: true,
}); });
const encryptedContext = await encrypt(sharedSecret(), currentValue); const encryptedContext = await encrypt(currentSharedSecret, currentValue);
send("message_send", { send("message_send", {
height: 0, height: 0,

View file

@ -26,11 +26,13 @@ export default function Screen() {
} | null>(null); } | null>(null);
const chatUserId = userId(); const chatUserId = userId();
const hasValidChatUser = Number.isSafeInteger(chatUserId) && chatUserId > 0;
const messagesQuery = useInfiniteQuery({ const messagesQuery = useInfiniteQuery({
queryKey: ["chat-messages", String(chatUserId)], queryKey: ["chat-messages", String(chatUserId)],
initialPageParam: 0, initialPageParam: 0,
queryFn: ({ pageParam }) => getMessages(PAGE_SIZE, Number(pageParam)), queryFn: ({ pageParam }) => getMessages(PAGE_SIZE, Number(pageParam)),
enabled: hasValidChatUser,
getNextPageParam: (lastPage, allPages) => { getNextPageParam: (lastPage, allPages) => {
if (lastPage.length < PAGE_SIZE) { if (lastPage.length < PAGE_SIZE) {
return undefined; return undefined;
@ -175,6 +177,14 @@ export default function Screen() {
void onScroll(); void onScroll();
}, [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 ( return (
<div className="w-full h-full flex flex-col overflow-hidden px-2"> <div className="w-full h-full flex flex-col overflow-hidden px-2">
<div <div