| ... | @@ -26,6 +26,7 @@ import { AppText } from "../../components/AppText"; | ... | @@ -26,6 +26,7 @@ import { AppText } from "../../components/AppText"; |
| 26 | import { downloadAndShareAttachment } from "../../lib/attachmentDownload"; | 26 | import { downloadAndShareAttachment } from "../../lib/attachmentDownload"; |
| 27 | import { beginForegroundHandoff } from "../../lib/foreground-handoff"; | 27 | import { beginForegroundHandoff } from "../../lib/foreground-handoff"; |
| 28 | import { usePreviewStreamAccess } from "../../state/preview"; | 28 | import { usePreviewStreamAccess } from "../../state/preview"; |
| | 29 | import { previewPromptText } from "./previewPromptText"; |
| 29 | | 30 | |
| 30 | import { | 31 | import { |
| 31 | previewStreamDocument, | 32 | previewStreamDocument, |
| ... | @@ -256,6 +257,7 @@ function PreviewStreamDocumentView({ | ... | @@ -256,6 +257,7 @@ function PreviewStreamDocumentView({ |
| 256 | const [hostSetup, setHostSetup] = useState<PreviewStreamHostSetup | null>(null); | 257 | const [hostSetup, setHostSetup] = useState<PreviewStreamHostSetup | null>(null); |
| 257 | const [started, setStarted] = useState(false); | 258 | const [started, setStarted] = useState(false); |
| 258 | const [control, setControl] = useState<PreviewStreamControl | null>(null); | 259 | const [control, setControl] = useState<PreviewStreamControl | null>(null); |
| | 260 | const dialogRef = useRef<PreviewStreamControl["dialog"]>(null); |
| 259 | const [promptText, setPromptText] = useState(""); | 261 | const [promptText, setPromptText] = useState(""); |
| 260 | const [fileChooser, setFileChooser] = useState<PreviewStreamFileChooser | null>(null); | 262 | const [fileChooser, setFileChooser] = useState<PreviewStreamFileChooser | null>(null); |
| 261 | const answerFileChooser = (pick: boolean) => { | 263 | const answerFileChooser = (pick: boolean) => { |
| ... | @@ -371,11 +373,14 @@ function PreviewStreamDocumentView({ | ... | @@ -371,11 +373,14 @@ function PreviewStreamDocumentView({ |
| 371 | const message = previewStreamMessage(event.nativeEvent.data); | 373 | const message = previewStreamMessage(event.nativeEvent.data); |
| 372 | if (message === null) return; | 374 | if (message === null) return; |
| 373 | switch (message.type) { | 375 | switch (message.type) { |
| 374 | case "control": | 376 | case "control": { |
| 375 | setControl(message); | 377 | setControl(message); |
| 376 | setPromptText(message.dialog?.defaultValue ?? ""); | 378 | const previousDialog = dialogRef.current; |
| | 379 | dialogRef.current = message.dialog; |
| | 380 | setPromptText((draft) => previewPromptText(previousDialog, message.dialog, draft)); |
| 377 | onControl?.(message); | 381 | onControl?.(message); |
| 378 | return; | 382 | return; |
| | 383 | } |
| 379 | case "unauthorized": | 384 | case "unauthorized": |
| 380 | if (!onUnauthorized()) { | 385 | if (!onUnauthorized()) { |
| 381 | fail("This session can't open the browser stream. Reconnect to try again."); | 386 | fail("This session can't open the browser stream. Reconnect to try again."); |
| ... | @@ -413,6 +418,8 @@ function PreviewStreamDocumentView({ | ... | @@ -413,6 +418,8 @@ function PreviewStreamDocumentView({ |
| 413 | } | 418 | } |
| 414 | setStatus(message.status); | 419 | setStatus(message.status); |
| 415 | if (message.status === "connecting") { | 420 | if (message.status === "connecting") { |
| | 421 | // Dialogs may have closed and reopened while this viewer was disconnected. |
| | 422 | dialogRef.current = null; |
| 416 | setControl(null); | 423 | setControl(null); |
| 417 | onControl?.(null); | 424 | onControl?.(null); |
| 418 | } | 425 | } |