Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { SidebarChromeHeader } from "./sidebar/SidebarChrome";
import { MainAppLocationTracker } from "./sidebar/mainAppLocation";
import { useSidebarStageBackdropVariant } from "./SidebarStageBackdrop";
import { useProjects } from "../state/entities";
import { ProfileAwareSidebar } from "../profileScope/ProfileAwareSidebar";
import {
resolveInitialThreadSidebarWidth,
resolveThreadSidebarMaximumWidth,
Expand Down Expand Up @@ -316,16 +317,18 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
onResize: setSidebarWidth,
}}
>
{isOnSettings ? (
<>
<SidebarChromeHeader isElectron={isElectron} />
<SettingsSidebarNav pathname={pathname} />
</>
) : legacySidebarEnabled ? (
<LegacyThreadSidebar />
) : (
<ThreadSidebar />
)}
<ProfileAwareSidebar>
{isOnSettings ? (
<>
<SidebarChromeHeader isElectron={isElectron} />
<SettingsSidebarNav pathname={pathname} />
</>
) : legacySidebarEnabled ? (
<LegacyThreadSidebar />
) : (
<ThreadSidebar />
)}
</ProfileAwareSidebar>
<SidebarRail onDoubleClick={resetSidebarWidth} />
</Sidebar>
{children}
Expand Down
40 changes: 32 additions & 8 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ import {
useThreadShells,
} from "../state/entities";
import { environmentServerConfigsAtom, primaryServerKeybindingsAtom } from "../state/server";
import { intersectProjectKeys } from "@t3tools/client-runtime/state/profile-scope";
import { ProfileSwitcher } from "../profileScope/ProfileSwitcher";
import { useProfileScopedProjectKeys } from "../profileScope/useProfileScope";
import { vcsEnvironment } from "../state/vcs";
import { threadEnvironment } from "../state/threads";
import { useEnvironmentQuery } from "../state/query";
Expand Down Expand Up @@ -2350,10 +2353,24 @@ export default function Sidebar() {
sidebarProjectSortOrder,
],
);
const projectGroups = useMemo(
const allProjectGroups = useMemo(
() => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
[sidebarProjectSortOrder, threads, unsortedProjectGroups],
);
// Fork (profiles): the active provider profile narrows everything below to its projects;
// null shows all.
const profileProjectKeys = useProfileScopedProjectKeys();
const projectGroups = useMemo(
() =>
profileProjectKeys === null
? allProjectGroups
: allProjectGroups.filter((group) =>
group.memberProjectRefs.some((ref) =>
profileProjectKeys.has(`${ref.environmentId}:${ref.projectId}`),
),
),
[allProjectGroups, profileProjectKeys],
);
const projectGroupsRef = useRef(projectGroups);
projectGroupsRef.current = projectGroups;
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
Expand Down Expand Up @@ -2461,14 +2478,19 @@ export default function Sidebar() {
);
const scopedProjectKeys = useMemo(
() =>
scopedProjectGroup === null
? null
: new Set(
scopedProjectGroup.memberProjectRefs.map(
(projectRef) => `${projectRef.environmentId}:${projectRef.projectId}`,
// Fork (profiles): a project group can span environments whose members use different
// profiles, so a chosen project only keeps its members in the active profile.
intersectProjectKeys(
scopedProjectGroup === null
? null
: new Set(
scopedProjectGroup.memberProjectRefs.map(
(projectRef) => `${projectRef.environmentId}:${projectRef.projectId}`,
),
),
),
[scopedProjectGroup],
profileProjectKeys,
),
[profileProjectKeys, scopedProjectGroup],
);
// A persisted scope whose project is gone falls back to all projects, but
// only after every catalog environment has a live project snapshot. Cached
Expand Down Expand Up @@ -4451,6 +4473,8 @@ export default function Sidebar() {
// Lifted above the stage backdrop, whose fade bleeds below the
// header and would otherwise paint across the search row's outline.
<SidebarGroup className="z-[1]">
{/* Fork (profiles) */}
<ProfileSwitcher />
<SidebarNotesLink />
<SidebarAutomationsLink />
<SidebarThreadHeader
Expand Down
62 changes: 62 additions & 0 deletions apps/web/src/profileScope/ProfileAwareSidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { scopedThreadKey } from "@t3tools/client-runtime/environment";
import {
followNavigation,
profileScopeProjectKey,
type ProfileNavigation,
} from "@t3tools/client-runtime/state/profile-scope";
import { useParams } from "@tanstack/react-router";
import { useEffect, useRef, type ReactNode } from "react";

import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { resolveThreadRouteTarget } from "../threadRoutes";
import { ProfileScopeShortcuts } from "./ProfileSwitcher";
import { useProfileScopeState } from "./useProfileScope";

/**
* The sidebar shows the profile of the thread you open. Opening one from a notification, search
* or link, or picking another project for a draft, switches to its project's profile. A profile
* chosen by hand holds until the next navigation.
*/
function ProfileFollowsActiveProject() {
const routeKey = useParams({
strict: false,
select: (params) => {
const target = resolveThreadRouteTarget(params);
if (target === null) return null;
return target.kind === "server"
? `thread:${scopedThreadKey(target.threadRef)}`
: `draft:${target.draftId}`;
},
});
const { activeDraftThread, activeThread } = useHandleNewThread();
const thread = activeThread ?? activeDraftThread;
const projectKey = thread ? profileScopeProjectKey(thread.environmentId, thread.projectId) : null;
const { scope, setScope, projectProfiles } = useProfileScopeState();
const followedRef = useRef<ProfileNavigation | null>(null);
useEffect(() => {
if (routeKey === null || projectKey === null) return;
const current = { routeKey, projectKey };
const outcome = followNavigation({
followed: followedRef.current,
current,
scope,
projectProfiles,
});
// Until the project's snapshot lands its profile is unknown, not "none": try again then.
if (outcome.kind === "pending") return;
followedRef.current = current;
if (outcome.kind === "switch") setScope(outcome.scope);
}, [projectKey, projectProfiles, routeKey, scope, setScope]);
return null;
}

/** Wraps the app sidebar's content with the profile shortcuts and the follow-the-project rule. */
export function ProfileAwareSidebar({ children }: { children: ReactNode }) {
return (
<>
<ProfileScopeShortcuts />
<ProfileFollowsActiveProject />
{children}
</>
);
}
Loading
Loading