import { useQuery } from "@tanstack/react-query"; import { useRouter } from "expo-router"; import React, { useEffect, useRef } from "react"; import { Text, View } from "react-native"; import { useApp } from "../../src/app-context"; import { AppHeader } from "../../src/components/AppHeader"; import { ChatScreenHeader } from "../../src/components/ChatScreenHeader"; import { GuestAuthGate } from "../../src/components/GuestAuthGate"; import { ScreenShell } from "../../src/components/ScreenShell"; import { bindPendingFileIntent, bindPendingTextIntent, loadPendingTextIntent, pendingDialogKey, } from "../../src/pending-intent"; import { dialogApi } from "../../src/services"; import { ErrorNotice, Loading, styles } from "../../src/ui"; import { spacing } from "../../src/theme"; export default function DialogsScreen() { const app = useApp(); const router = useRouter(); const requestKey = useRef(pendingDialogKey() ?? crypto.randomUUID()); const chat = useQuery({ queryKey: ["current-dialog", requestKey.current], queryFn: () => dialogApi.create(requestKey.current), enabled: app.authStatus === "authenticated", }); useEffect(() => { if (chat.data) { const intent = loadPendingTextIntent(); if (intent && !intent.dialogId) bindPendingTextIntent(intent, chat.data.dialog_id); bindPendingFileIntent(chat.data.dialog_id); router.replace(`/dialogs/${chat.data.dialog_id}`); } }, [chat.data, router]); if (app.authStatus !== "authenticated") { return ( ); } return ( Открываем чат… {chat.isLoading && } {chat.error && void chat.refetch()} />} ); }