Fixed reload bug when clicking on a user
This commit is contained in:
parent
0e5a010937
commit
00659c4001
3 changed files with 34 additions and 5 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue