diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx index aefa9ab9f4..07ec0dc907 100644 --- a/apps/web/src/components/AppSidebarLayout.tsx +++ b/apps/web/src/components/AppSidebarLayout.tsx @@ -1,5 +1,5 @@ import { useAtomValue } from "@effect/atom-react"; -import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from "react"; +import { useEffect, useState, type CSSProperties, type ReactNode } from "react"; import { useLocation, useNavigate } from "@tanstack/react-router"; import { isElectron } from "../env"; @@ -56,8 +56,6 @@ function SidebarControl() { export function AppSidebarLayout({ children }: { children: ReactNode }) { const navigate = useNavigate(); const pathname = useLocation({ select: (location) => location.pathname }); - const pathnameRef = useRef(pathname); - pathnameRef.current = pathname; const isMacosDesktop = isElectron && isMacPlatform(navigator.platform); const [isWindowFullscreen, setIsWindowFullscreen] = useState(() => { const getWindowFullscreenState = window.desktopBridge?.getWindowFullscreenState; @@ -95,7 +93,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { const unsubscribe = onMenuAction((action) => { if (action === "open-settings") { - const isSettingsRoute = /^\/settings(\/|$)/.test(pathnameRef.current); + const isSettingsRoute = /^\/settings(\/|$)/.test(pathname); if (!isSettingsRoute) { void navigate({ to: "/settings" }); } @@ -105,7 +103,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { return () => { unsubscribe?.(); }; - }, [navigate]); + }, [navigate, pathname]); return ( diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 7406f8077a..9bb04e9e53 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -218,7 +218,7 @@ import { DRAFT_HERO_TRANSITION_ANIMATION_ID, DRAFT_HERO_TRANSITION_DURATION_MS, DRAFT_HERO_TRANSITION_EASING, - MOBILE_COMPOSER_CHROME_VIEW_TRANSITION_NAME, + MOBILE_COMPOSER_VIEW_TRANSITION_NAME, MOBILE_DRAFT_HEADLINE_VIEW_TRANSITION_NAME, runMobileComposerTransition, } from "./chat/draftHeroTransition"; @@ -4084,6 +4084,7 @@ function ChatViewContent(props: ChatViewProps) { return; } + sendInFlightRef.current = true; if (isDraftHeroState && activeThreadKey) { let resolveDockStarted: (() => void) | undefined; const dockStarted = new Promise((resolve) => { @@ -4099,7 +4100,6 @@ function ChatViewContent(props: ChatViewProps) { void dockTransition.catch(() => resolveDockStarted?.()); await dockStarted; } - sendInFlightRef.current = true; beginLocalDispatch({ preparingWorktree: Boolean(baseBranchForWorktree) }); const composerImagesSnapshot = [...composerImages]; @@ -5295,132 +5295,135 @@ function ChatViewContent(props: ChatViewProps) { )}
- -
-
- {isGitRepo && ( -
- -
+ +
+
+
+ {isGitRepo && ( +
+ +
+ )} +
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index 574e33d4da..5f6c234e5f 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -19,6 +19,7 @@ import { resolveThreadStatusPill, shouldClearThreadSelectionOnMouseDown, sortProjectsForSidebar, + sortScopedProjectsForSidebar, THREAD_JUMP_HINT_SHOW_DELAY_MS, } from "./Sidebar.logic"; import { @@ -1066,3 +1067,73 @@ describe("sortProjectsForSidebar", () => { expect(timestamp).toBe(Date.parse("2026-03-09T10:10:00.000Z")); }); }); + +describe("sortScopedProjectsForSidebar", () => { + it("keeps identical project ids in different environments separate", () => { + const remoteEnvironmentId = EnvironmentId.make("environment-remote"); + const sharedProjectId = ProjectId.make("shared-project"); + const projects = [ + makeProject({ + environmentId: localEnvironmentId, + id: sharedProjectId, + title: "Local project", + }), + makeProject({ + environmentId: remoteEnvironmentId, + id: sharedProjectId, + title: "Remote project", + }), + ]; + const threads = [ + makeThread({ + environmentId: localEnvironmentId, + projectId: sharedProjectId, + updatedAt: "2026-03-09T10:02:00.000Z", + }), + makeThread({ + environmentId: remoteEnvironmentId, + projectId: sharedProjectId, + updatedAt: "2026-03-09T10:10:00.000Z", + }), + ]; + + const sorted = sortScopedProjectsForSidebar(projects, threads, "updated_at"); + + expect(sorted.map((project) => project.title)).toEqual(["Remote project", "Local project"]); + }); + + it("does not use archived threads as project activity", () => { + const projects = [ + makeProject({ + id: ProjectId.make("project-visible"), + title: "Visible project", + updatedAt: "2026-03-09T10:01:00.000Z", + }), + makeProject({ + id: ProjectId.make("project-archived"), + title: "Archived-only project", + updatedAt: "2026-03-09T10:00:00.000Z", + }), + ]; + const threads = [ + makeThread({ + id: ThreadId.make("thread-visible"), + projectId: ProjectId.make("project-visible"), + updatedAt: "2026-03-09T10:02:00.000Z", + }), + makeThread({ + id: ThreadId.make("thread-archived"), + projectId: ProjectId.make("project-archived"), + updatedAt: "2026-03-09T10:10:00.000Z", + archivedAt: "2026-03-09T10:11:00.000Z", + }), + ]; + + const sorted = sortScopedProjectsForSidebar(projects, threads, "updated_at"); + + expect(sorted.map((project) => project.title)).toEqual([ + "Visible project", + "Archived-only project", + ]); + }); +}); diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index 4e7614ed55..91a61cc155 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -24,6 +24,16 @@ type SidebarProject = { updatedAt?: string | undefined; }; +type ScopedSidebarProject = SidebarProject & { + environmentId: string; +}; + +type ScopedSidebarThread = ThreadSortInput & { + environmentId: string; + projectId: string; + archivedAt: string | null; +}; + export type ThreadTraversalDirection = "previous" | "next"; export interface ThreadStatusPill { @@ -534,6 +544,25 @@ export function getProjectSortTimestamp( return toSortableTimestamp(project.updatedAt ?? project.createdAt) ?? Number.NEGATIVE_INFINITY; } +function sortProjectsByActivity( + projects: readonly TProject[], + sortOrder: SidebarProjectSortOrder, + getProjectThreads: (project: TProject) => readonly ThreadSortInput[], + compareTies: (left: TProject, right: TProject) => number, +): TProject[] { + if (sortOrder === "manual") { + return [...projects]; + } + + return [...projects].toSorted((left, right) => { + const rightTimestamp = getProjectSortTimestamp(right, getProjectThreads(right), sortOrder); + const leftTimestamp = getProjectSortTimestamp(left, getProjectThreads(left), sortOrder); + const byTimestamp = + rightTimestamp === leftTimestamp ? 0 : rightTimestamp > leftTimestamp ? 1 : -1; + return byTimestamp || compareTies(left, right); + }); +} + export function sortProjectsForSidebar< TProject extends SidebarProject, TThread extends Pick & ThreadSortInput, @@ -542,10 +571,6 @@ export function sortProjectsForSidebar< threads: readonly TThread[], sortOrder: SidebarProjectSortOrder, ): TProject[] { - if (sortOrder === "manual") { - return [...projects]; - } - const threadsByProjectId = new Map(); for (const thread of threads) { const existing = threadsByProjectId.get(thread.projectId) ?? []; @@ -553,20 +578,47 @@ export function sortProjectsForSidebar< threadsByProjectId.set(thread.projectId, existing); } - return [...projects].toSorted((left, right) => { - const rightTimestamp = getProjectSortTimestamp( - right, - threadsByProjectId.get(right.id) ?? [], - sortOrder, - ); - const leftTimestamp = getProjectSortTimestamp( - left, - threadsByProjectId.get(left.id) ?? [], - sortOrder, - ); - const byTimestamp = - rightTimestamp === leftTimestamp ? 0 : rightTimestamp > leftTimestamp ? 1 : -1; - if (byTimestamp !== 0) return byTimestamp; - return left.title.localeCompare(right.title) || left.id.localeCompare(right.id); - }); + return sortProjectsByActivity( + projects, + sortOrder, + (project) => threadsByProjectId.get(project.id) ?? [], + (left, right) => left.title.localeCompare(right.title) || left.id.localeCompare(right.id), + ); +} + +/** + * Sorts the cross-environment project collection used by landing surfaces. + * Project ids are only unique within an environment, and archived threads + * must not make a project appear recently active. + */ +export function sortScopedProjectsForSidebar< + TProject extends ScopedSidebarProject, + TThread extends ScopedSidebarThread, +>( + projects: readonly TProject[], + threads: readonly TThread[], + sortOrder: SidebarProjectSortOrder, +): TProject[] { + const scopedKey = (environmentId: string, projectId: string) => + `${environmentId}\u0000${projectId}`; + const threadsByProject = new Map(); + for (const thread of threads) { + if (thread.archivedAt !== null) { + continue; + } + const key = scopedKey(thread.environmentId, thread.projectId); + const existing = threadsByProject.get(key) ?? []; + existing.push(thread); + threadsByProject.set(key, existing); + } + + return sortProjectsByActivity( + projects, + sortOrder, + (project) => threadsByProject.get(scopedKey(project.environmentId, project.id)) ?? [], + (left, right) => + left.title.localeCompare(right.title) || + left.environmentId.localeCompare(right.environmentId) || + left.id.localeCompare(right.id), + ); } diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 9c28fca85c..ad9a364bd5 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -78,7 +78,6 @@ import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel"; import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner"; import { resolveComposerMenuActiveItemId } from "./composerMenuHighlight"; import { searchSlashCommandItems } from "./composerSlashCommandSearch"; -import { MOBILE_COMPOSER_VIEW_TRANSITION_NAME } from "./draftHeroTransition"; import { getComposerPromptInjectionState, getComposerProviderState, @@ -2062,9 +2061,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) onSubmit={submitComposer} className="mx-auto w-full min-w-0 max-w-3xl" data-chat-composer-form="true" - style={ - isMobileViewport ? { viewTransitionName: MOBILE_COMPOSER_VIEW_TRANSITION_NAME } : undefined - } >
sortProjectsForSidebar(projects, threads, "updated_at"), + () => sortScopedProjectsForSidebar(projects, threads, "updated_at"), [projects, threads], ); const projectByKey = useMemo( @@ -91,7 +91,13 @@ export function DraftHeroHeadline({ ) : ( - {activeProjectTitle ?? "Add a project"} + ); return ( diff --git a/apps/web/src/components/chat/draftHeroTransition.ts b/apps/web/src/components/chat/draftHeroTransition.ts index 8e2c1ec85d..0773407cfc 100644 --- a/apps/web/src/components/chat/draftHeroTransition.ts +++ b/apps/web/src/components/chat/draftHeroTransition.ts @@ -1,8 +1,7 @@ export const DRAFT_HERO_TRANSITION_ANIMATION_ID = "t3-draft-hero-transition"; export const DRAFT_HERO_TRANSITION_DURATION_MS = 180; -export const DRAFT_HERO_TRANSITION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)"; +export const DRAFT_HERO_TRANSITION_EASING = "cubic-bezier(0.4, 0, 0.2, 1)"; export const MOBILE_COMPOSER_VIEW_TRANSITION_NAME = "t3-mobile-composer"; -export const MOBILE_COMPOSER_CHROME_VIEW_TRANSITION_NAME = "t3-mobile-composer-chrome"; export const MOBILE_DRAFT_HEADLINE_VIEW_TRANSITION_NAME = "t3-mobile-draft-headline"; type ComposerViewTransition = { diff --git a/apps/web/src/index.css b/apps/web/src/index.css index 5171ba6131..c500eb68d7 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -11,38 +11,34 @@ html[data-mobile-composer-route-transition="true"]::view-transition-new(root) { animation: none; } -html[data-mobile-composer-route-transition="true"]::view-transition-group(t3-mobile-composer), -html[data-mobile-composer-route-transition="true"]::view-transition-group(t3-mobile-composer-chrome) { +html[data-mobile-composer-route-transition="true"]::view-transition-group(t3-mobile-composer) { animation-duration: 180ms; animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); } -html[data-mobile-composer-route-transition="true"]::view-transition-image-pair(t3-mobile-composer), -html[data-mobile-composer-route-transition="true"]::view-transition-image-pair(t3-mobile-composer-chrome) { +html[data-mobile-composer-route-transition="true"]::view-transition-image-pair(t3-mobile-composer) { isolation: isolate; } -html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobile-composer), -html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobile-composer-chrome) { +html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobile-composer) { animation: t3-mobile-composer-old 180ms linear both; mix-blend-mode: normal; } -html[data-mobile-composer-route-transition="true"]::view-transition-new(t3-mobile-composer), -html[data-mobile-composer-route-transition="true"]::view-transition-new(t3-mobile-composer-chrome) { +html[data-mobile-composer-route-transition="true"]::view-transition-new(t3-mobile-composer) { animation: t3-mobile-composer-new 180ms linear both; mix-blend-mode: normal; } -/* The expanded and compact composers have different internal layouts. Keep - one snapshot visible at a time so their controls cannot ghost over each - other while the shared geometry continues moving and resizing. */ +/* The expanded and compact composers have different internal layouts. Use a + brief crossfade while their shared wrapper moves so the layout change does + not read as a single-frame cut. */ @keyframes t3-mobile-composer-old { 0%, - 54.99% { + 35% { opacity: 1; } - 55%, + 65%, 100% { opacity: 0; } @@ -50,10 +46,10 @@ html[data-mobile-composer-route-transition="true"]::view-transition-new(t3-mobil @keyframes t3-mobile-composer-new { 0%, - 54.99% { + 35% { opacity: 0; } - 55%, + 65%, 100% { opacity: 1; } diff --git a/apps/web/src/routes/_chat.draft.$draftId.tsx b/apps/web/src/routes/_chat.draft.$draftId.tsx index 10159e7399..74c1b15c07 100644 --- a/apps/web/src/routes/_chat.draft.$draftId.tsx +++ b/apps/web/src/routes/_chat.draft.$draftId.tsx @@ -66,19 +66,6 @@ function DraftChatThreadRouteView() { void navigate({ to: "/", replace: true }); }, [canonicalThreadRef, draftSession, navigate]); - if (canonicalThreadRef) { - return ( - - - - ); - } - if (!draftSession) { return null; } diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx index 48462b937a..8aadbf9ea2 100644 --- a/apps/web/src/routes/_chat.index.tsx +++ b/apps/web/src/routes/_chat.index.tsx @@ -1,10 +1,10 @@ import { scopeProjectRef } from "@t3tools/client-runtime/environment"; import { createFileRoute, Link } from "@tanstack/react-router"; -import { LinkIcon, PlusIcon } from "lucide-react"; -import { useEffect, useMemo, useRef } from "react"; +import { LinkIcon, PlusIcon, RotateCcwIcon } from "lucide-react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { useOpenAddProjectCommandPalette } from "../commandPaletteContext"; -import { sortProjectsForSidebar } from "../components/Sidebar.logic"; +import { sortScopedProjectsForSidebar } from "../components/Sidebar.logic"; import { Button } from "../components/ui/button"; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../components/ui/empty"; import { SidebarInset } from "../components/ui/sidebar"; @@ -42,10 +42,13 @@ function IndexDraftLanding() { const bootstrapped = useAllEnvironmentShellsBootstrapped(); const handleNewThread = useNewThreadHandler(); const startingRef = useRef(false); + const [startState, setStartState] = useState({ failed: false, retryRequest: 0 }); const mostRecentProject = useMemo( () => - bootstrapped ? (sortProjectsForSidebar(projects, threads, "updated_at")[0] ?? null) : null, + bootstrapped + ? (sortScopedProjectsForSidebar(projects, threads, "updated_at")[0] ?? null) + : null, [bootstrapped, projects, threads], ); @@ -58,15 +61,49 @@ function IndexDraftLanding() { replace: true, }).catch(() => { startingRef.current = false; + setStartState((state) => ({ ...state, failed: true })); }); - }, [handleNewThread, mostRecentProject]); + }, [handleNewThread, mostRecentProject, startState.retryRequest]); - if (!bootstrapped || mostRecentProject !== null) { + if (!bootstrapped) { return null; } + if (mostRecentProject !== null) { + return startState.failed ? ( + { + setStartState((state) => ({ + failed: false, + retryRequest: state.retryRequest + 1, + })); + }} + /> + ) : null; + } return ; } +function DraftStartError({ onRetry }: { readonly onRetry: () => void }) { + return ( + + + + Couldn’t start a new thread + + The project is still available. Try opening the draft again. + +
+ +
+
+
+
+ ); +} + function NoProjectsHero() { const openAddProject = useOpenAddProjectCommandPalette();