GeezerVison is showing github.com — fix(web): keep later navigation when thread deletion completes by Edge358 · Pull Request #33953 · pingdotgg/t3code
fix(web): keep later navigation when thread deletion completes
#33953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(3)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -55,7 +55,11 @@ vi.mock("react", () => ({
useRef: (current: unknown) => ({ current }),
}));
vi.mock("@tanstack/react-router", () => ({
useRouter: () => ({ state: { location: { href: "/" }, matches: [] }, navigate: async () => {} }),
useRouter: () => ({
state: { location: { href: "/" }, matches: [] },
history: { subscribe: () => () => {} },
navigate: async () => {},
}),
}));
vi.mock("../state/session", () => ({
environmentSession: { sessionStateAtom: "session" },
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -587,10 +587,16 @@ export function useThreadActions() {
sortOrder: sidebarThreadSortOrder,
now: new Date().toISOString(),
});
let navigatedDuringDelete = false;
// The missing-thread redirect and the index draft replace this entry; any other history
// action while the delete is pending is the user's own choice, which must win.
const stopWatchingHistory = router.history.subscribe(({ action }) => {
if (action.type !== "REPLACE") navigatedDuringDelete = true;
});
const deleteResult = await deleteThreadMutation({
environmentId: threadRef.environmentId,
input: { threadId: threadRef.threadId },
});
}).finally(stopWatchingHistory) ;
if (deleteResult._tag === "Failure") {
return deleteResult;
}
Expand All
@@ -614,7 +620,7 @@ export function useThreadActions() {
clearTerminalUiState(threadRef);
clearDeletedThreadPanelState(threadRef);
if (shouldNavigateToFallback) {
if (shouldNavigateToFallback && !navigatedDuringDelete ) {
const fallbackThread = fallbackThreadId
? readThreadShell(scopeThreadRef(threadRef.environmentId, fallbackThreadId))
: null;
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -18,10 +18,20 @@ const commands = vi.hoisted(() => ({
snooze: vi.fn(),
unsnooze: vi.fn(),
}));
const router = vi.hoisted(() => ({
navigate: vi.fn(async () => {}),
state: { location: { href: "/" }, matches: [{ params: {} as Record<string, string> }] },
}));
const router = vi.hoisted(() => {
const listeners = new Set<(event: { action: { type: string } }) => void>();
return {
navigate: vi.fn(async () => {}),
state: { location: { href: "/" }, matches: [{ params: {} as Record<string, string> }] },
history: {
listeners,
subscribe: (listener: (event: { action: { type: string } }) => void) => {
listeners.add(listener);
return () => listeners.delete(listener);
},
},
};
});
vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
vi.mock("../state/session", async (original) => ({
...(await original<typeof import("../state/session")>()),
Expand Down
Expand Up
@@ -239,6 +249,25 @@ describe("archive navigation", () => {
});
});
describe("delete navigation", () => {
it.each([
{ type: "REPLACE", by: "the app's missing-thread redirect", fallsBack: true },
{ type: "PUSH", by: "the user opening another thread", fallsBack: false },
])("falls back: $fallsBack after $by while deleting", async ({ type, fallsBack }) => {
router.state.matches[0]!.params = {
environmentId: target.environmentId,
threadId: target.threadId,
};
commands.delete.mockImplementation(async () => {
for (const listener of router.history.listeners) listener({ action: { type } });
return { _tag: "Success", value: undefined };
});
expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
expect(router.navigate).toHaveBeenCalledTimes(fallsBack ? 1 : 0);
expect(router.history.listeners.size).toBe(0);
});
});
describe("settle and snooze Undo", () => {
it("un-settles from the notice and expires the Undo after a manual un-settle", async () => {
const add = vi.spyOn(toastManager, "add").mockReturnValue("toast");
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.