Skip to content

Commit 609f327

Browse files
committed
fix(web): recover drafts for archived checkouts
1 parent 1fea01a commit 609f327

6 files changed

Lines changed: 717 additions & 71 deletions

File tree

‎apps/web/src/components/ThreadRouteView.tsx‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
22
import type { ScopedThreadRef } from "@t3tools/contracts";
3-
import { useNavigate } from "@tanstack/react-router";
3+
import { useLocation, useNavigate } from "@tanstack/react-router";
44
import { useEffect, useState } from "react";
55

66
import ChatView from "./ChatView";
@@ -38,6 +38,7 @@ import {
3838
*/
3939
export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) {
4040
const navigate = useNavigate();
41+
const archiveDraftRetry = useLocation({ select: (location) => location.state.archiveDraftRetry });
4142
const draftId = target.kind === "draft" ? target.draftId : null;
4243
const draftSession = useComposerDraftStore((store) =>
4344
draftId === null ? null : store.getDraftSession(draftId),
@@ -151,11 +152,21 @@ export function ThreadRouteView({ target }: { target: ThreadRouteTarget }) {
151152
if (renderState === "missing") {
152153
const { clearPendingFileDropsForThread } = useSidebarPendingFileDropStore.getState();
153154
clearPendingFileDropsForThread(target.threadRef);
154-
if (environmentHasAnyThreads) {
155+
if (archiveDraftRetry && scopedThreadKey(archiveDraftRetry.threadRef) === serverThreadKey) {
156+
void navigate({ to: "/", replace: true, state: { archiveDraftRetry } });
157+
} else if (environmentHasAnyThreads) {
155158
void navigate({ to: "/", replace: true });
156159
}
157160
}
158-
}, [bootstrapComplete, environmentHasAnyThreads, navigate, renderState, target]);
161+
}, [
162+
archiveDraftRetry,
163+
bootstrapComplete,
164+
environmentHasAnyThreads,
165+
navigate,
166+
renderState,
167+
serverThreadKey,
168+
target,
169+
]);
159170

160171
useEffect(() => {
161172
if (target.kind !== "server" || !serverThreadStarted || !draftThread) {

0 commit comments

Comments
 (0)