@devries-cameron20 / t3code-1 / commits / c38b265adc
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(web): filter the sidebar by several projects at once (#25284)

maria committed Oct 28, 2026 at 00:05 UTC c38b265adc40f44fe23caeef3941a5a466ec595b
4 files changed +180 -67
apps/web/src/components/Sidebar.tsx
+124 -50
@@ -59,7 +59,14 @@ import {
59 } from "@t3tools/contracts";
60 import type { OlderSettledScope } from "@t3tools/client-runtime/state/threads";
61
62 -import { ChevronDownIcon, FolderIcon, ListFilterIcon, PlusIcon, SettingsIcon } from "lucide-react";
62 +import {
63 + CheckIcon,
64 + ChevronDownIcon,
65 + FolderIcon,
66 + ListFilterIcon,
67 + PlusIcon,
68 + SettingsIcon,
69 +} from "lucide-react";
70 import {
71 useEffect,
72 useLayoutEffect,
@@ -98,7 +105,7 @@ import { useSidebarPendingFileDropStore } from "../sidebarPendingFileDropStore";
105 import { selectProjectGroupingSettings } from "../logicalProject";
106 import {
107 projectGroupsSpanEnvironments,
101 - resolveSidebarProjectScopeKey,
108 + resolveSidebarProjectScopeKeys,
109 getSidebarProjectSettingsKey,
110 type SidebarProjectSnapshot,
111 } from "../sidebarProjectGrouping";
@@ -755,6 +762,19 @@ function useSidebarLookups() {
762 };
763 }
764
765 +function ProjectScopeRowIcon(props: { isSelected: boolean; children: ReactNode }) {
766 + return (
767 + <span className="relative flex shrink-0">
768 + {props.children}
769 + {props.isSelected ? (
770 + <span className="pointer-events-none absolute -right-1 -bottom-1 grid size-3 place-items-center rounded-full bg-primary ring-2 ring-popover">
771 + <CheckIcon className="size-2 text-primary-foreground" strokeWidth={4} aria-hidden />
772 + </span>
773 + ) : null}
774 + </span>
775 + );
776 +}
777 +
778 function canOperateThreads(
779 threads: ReadonlyArray<Pick<SidebarThreadSummary, "environmentId">>,
780 ): boolean {
@@ -900,8 +920,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
920 );
921 const environmentMachineById = useEnvironmentMachines();
922 const projectGroupsRef = useRef(projectGroups);
903 - const persistedProjectScopeKey = useUiStateStore((store) => store.sidebarProjectScopeKey);
904 - const setPersistedProjectScopeKey = useUiStateStore((store) => store.setSidebarProjectScopeKey);
923 + const persistedProjectScopeKeys = useUiStateStore((store) => store.sidebarProjectScopeKeys);
924 + const setPersistedProjectScopeKeys = useUiStateStore((store) => store.setSidebarProjectScopeKeys);
925 const [projectScopeMenuState, dispatchProjectScopeMenu] = useReducer(
926 reduceSidebarProjectScopeMenuState,
927 { open: false, query: "" },
@@ -961,28 +981,29 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
981 const routeThreadKey = routeThreadRef ? scopedThreadKey(routeThreadRef) : null;
982
983 // A selection made under one scope can hold threads the next scope hides.
964 - const setProjectScopeKey = (key: string | null) => {
984 + const setProjectScopeKeys = (keys: readonly string[]) => {
985 clearSelection();
966 - setPersistedProjectScopeKey(key);
986 + setPersistedProjectScopeKeys(keys);
987 };
988 // A scope whose project is gone reads as all projects once every snapshot has
969 - // loaded. The stored key is left alone, so the scope returns with its project.
970 - const chosenProjectScopeKey = resolveSidebarProjectScopeKey({
989 + // loaded. The stored keys are left alone, so the scope returns with its project.
990 + const chosenProjectScopeKeys = resolveSidebarProjectScopeKeys({
991 groups: projectGroups,
972 - key: persistedProjectScopeKey,
992 + keys: persistedProjectScopeKeys,
993 settings: projectGroupingSettings,
994 canClearMissingScope: allProjectSnapshotsReady && allProjectConfigsReady,
995 });
976 - const chosenProjectGroup =
977 - chosenProjectScopeKey === null
978 - ? null
979 - : (projectGroups.find((project) => project.projectKey === chosenProjectScopeKey) ?? null);
996 + const chosenProjectGroups = projectGroups.filter((project) =>
997 + chosenProjectScopeKeys.includes(project.projectKey),
998 + );
999 const chosenScopeProjectKeys =
981 - chosenProjectGroup === null
1000 + chosenProjectGroups.length === 0
1001 ? null
1002 : new Set(
984 - chosenProjectGroup.memberProjectRefs.map(
985 - (projectRef) => `${projectRef.environmentId}:${projectRef.projectId}`,
1003 + chosenProjectGroups.flatMap((project) =>
1004 + project.memberProjectRefs.map(
1005 + (projectRef) => `${projectRef.environmentId}:${projectRef.projectId}`,
1006 + ),
1007 ),
1008 );
1009 const threads = useQuietThreadShells();
@@ -1013,7 +1034,14 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1034 delegatedUnderParent,
1035 findThread: (key) => threads.find((candidate) => threadShellKey(candidate) === key),
1036 });
1016 - const projectScopeKey = revealWidensScope ? null : chosenProjectScopeKey;
1037 + const projectScopeKeys = revealWidensScope ? [] : chosenProjectScopeKeys;
1038 + const projectScopeKey = projectScopeKeys.length === 0 ? null : projectScopeKeys.join("\n");
1039 + const toggleProjectScopeKey = (key: string) =>
1040 + setProjectScopeKeys(
1041 + projectScopeKeys.includes(key)
1042 + ? projectScopeKeys.filter((candidate) => candidate !== key)
1043 + : [...projectScopeKeys, key],
1044 + );
1045 // The widened scope outlives the reveal, so it is written back to the persisted
1046 // scope. Route changes arrive from history, links and the palette, and only this
1047 // component holds the project groups that decide a widening, so no single
@@ -1022,8 +1050,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1050 useEffect(() => {
1051 if (!revealWidensScope) return;
1052 clearSelection();
1025 - setPersistedProjectScopeKey(null);
1026 - }, [clearSelection, revealWidensScope, setPersistedProjectScopeKey]);
1053 + setPersistedProjectScopeKeys([]);
1054 + }, [clearSelection, revealWidensScope, setPersistedProjectScopeKeys]);
1055 const revealActiveRow = useActiveRowReveal(routeReveal, routeRowThreadKey);
1056 const showProjectEnvironments = projectGroupsSpanEnvironments(projectGroups);
1057 const scratchMachineLabelFor = (
@@ -1040,26 +1068,25 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1068 return environmentLabelById.get(thread.environmentId) ?? null;
1069 };
1070 const selectedProjectScopeItem =
1043 - projectScopeItems.find((item) => item.value === (projectScopeKey ?? "all")) ??
1044 - projectScopeItems[0]!;
1071 + projectScopeKeys.length > 1
1072 + ? null
1073 + : (projectScopeItems.find((item) => item.value === (projectScopeKeys[0] ?? "all")) ??
1074 + projectScopeItems[0]!);
1075 const filteredProjectScopeItems = filterSidebarProjectScopeItems({
1076 items: projectScopeItems,
1077 query: projectScopeMenuState.query,
1078 matches: (item, query) =>
1079 projectScopeFilter.contains(item, query, (candidate) => candidate.label),
1080 });
1051 - const scopedProjectGroup = revealWidensScope ? null : chosenProjectGroup;
1081 + const scopedProjectGroups = revealWidensScope ? [] : chosenProjectGroups;
1082 + const scopedProjectRefs = scopedProjectGroups.flatMap((project) => project.memberProjectRefs);
1083 const scopedProjectKeys = revealWidensScope ? null : chosenScopeProjectKeys;
1084 const threadSearch = useThreadSearch(
1085 searchEnvironmentIds,
1086 threadSearchQuery,
1056 - scopedProjectGroup === null
1087 + scopedProjectGroups.length === 0
1088 ? {}
1058 - : {
1059 - projectIds: scopedProjectGroup.memberProjectRefs.map(
1060 - (projectRef) => projectRef.projectId,
1061 - ),
1062 - },
1089 + : { projectIds: scopedProjectRefs.map((projectRef) => projectRef.projectId) },
1090 );
1091 const routeDraftIdForRows = routeTarget?.kind === "draft" ? routeTarget.draftId : null;
1092 const visibleDraftSessionCount = useComposerDraftStore((store) => {
@@ -2022,6 +2049,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2049 threadKey,
2050 currentThreadKey: readRouteThreadKey(router),
2051 action: "snooze",
2052 + // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
2053 now: new Date().toISOString(),
2054 thread: readThreadShell(threadRef),
2055 })
@@ -2061,6 +2089,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2089 );
2090 if (threadKeys.length === 0) return;
2091 const count = threadKeys.length;
2092 + // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
2093 const selectionNow = new Date();
2094 const selectedThreads = threadKeys.flatMap((threadKey) => {
2095 const thread = threadByKeyRef.current.get(threadKey);
@@ -2094,6 +2123,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2123 const unpinMenuItem = buildBulkUnpinContextMenuItem({
2124 pinnedCount: pinnedSelectedThreads.length,
2125 });
2126 + // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
2127 const snoozePresets = resolveSnoozePresets(new Date(), timestampFormat);
2128 const clicked = await settlePromise(() =>
2129 api.contextMenu.show(
@@ -2406,7 +2436,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2436 projectFilter: threadProjectGroup
2437 ? {
2438 label: threadProjectGroup.displayName,
2409 - isActive: projectScopeKey === threadProjectGroup.projectKey,
2439 + isActive: projectScopeKeys.includes(threadProjectGroup.projectKey),
2440 }
2441 : null,
2442 isPinned,
@@ -2444,10 +2474,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2474 switch (clicked.value) {
2475 case "filter-by-project":
2476 if (threadProjectGroup) {
2447 - setProjectScopeKey(
2448 - projectScopeKey === threadProjectGroup.projectKey
2449 - ? null
2450 - : threadProjectGroup.projectKey,
2477 + setProjectScopeKeys(
2478 + projectScopeKeys.includes(threadProjectGroup.projectKey)
2479 + ? []
2480 + : [threadProjectGroup.projectKey],
2481 );
2482 }
2483 return;
@@ -2732,7 +2762,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2762 itemToStringLabel={(item) => item.label}
2763 isItemEqualToValue={(a, b) => a.value === b.value}
2764 open={projectScopeMenuState.open}
2735 - onOpenChange={(open) => {
2765 + onOpenChange={(open, eventDetails) => {
2766 + if (eventDetails.isCanceled) return;
2767 if (open) suppressNextScopeChangeRef.current = false;
2768 dispatchProjectScopeMenu({ type: "open-changed", open });
2769 }}
@@ -2740,29 +2771,50 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2771 highlightedProjectScopeKeyRef.current = item?.value ?? null;
2772 }}
2773 value={selectedProjectScopeItem}
2743 - onValueChange={(item) => {
2774 + onValueChange={(item, eventDetails) => {
2775 if (suppressNextScopeChangeRef.current) {
2776 suppressNextScopeChangeRef.current = false;
2777 return;
2778 }
2779 if (!item) return;
2749 - setProjectScopeKey(item.value === "all" ? null : item.value);
2780 + if (item.value === "all") {
2781 + setProjectScopeKeys([]);
2782 + } else if (
2783 + eventDetails.event instanceof MouseEvent &&
2784 + eventDetails.event.shiftKey
2785 + ) {
2786 + // Canceling skips Base UI's commit, which would freeze the search query, and its close.
2787 + eventDetails.cancel();
2788 + toggleProjectScopeKey(item.value);
2789 + } else {
2790 + setProjectScopeKeys([item.value]);
2791 + }
2792 }}
2793 >
2794 <ComboboxTrigger
2795 render={
2796 <SidebarHeaderIconButton
2797 label={
2756 - scopedProjectGroup
2757 - ? `Filter threads by project: ${scopedProjectGroup.displayName}`
2798 + scopedProjectGroups.length > 0
2799 + ? `Filter threads by project: ${scopedProjectGroups.map((project) => project.displayName).join(", ")}`
2800 : "Filter threads by project"
2801 }
2802 />
2803 }
2804 >
2763 - {scopedProjectGroup ? (
2805 + {scopedProjectGroups.length > 1 ? (
2806 + <span className="flex shrink-0 -space-x-1.5">
2807 + {scopedProjectGroups.slice(0, 2).map((project) => (
2808 + <ProjectFavicon
2809 + key={project.projectKey}
2810 + project={project}
2811 + className="size-3.5"
2812 + />
2813 + ))}
2814 + </span>
2815 + ) : scopedProjectGroups[0] ? (
2816 <span className="flex shrink-0">
2765 - <ProjectFavicon project={scopedProjectGroup} className="size-4" />
2817 + <ProjectFavicon project={scopedProjectGroups[0]} className="size-4" />
2818 </span>
2819 ) : (
2820 <ListFilterIcon className="size-4" />
@@ -2781,15 +2833,27 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2833 if (
2834 event.defaultPrevented ||
2835 event.nativeEvent.isComposing ||
2836 + event.keyCode === 229 ||
2837 event.ctrlKey ||
2838 event.altKey ||
2786 - event.metaKey ||
2787 - (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10"))
2839 + event.metaKey
2840 ) {
2841 return;
2842 }
2843 const scopeKey = highlightedProjectScopeKeyRef.current;
2844 const project = scopeKey ? projectGroupByScopeKey.get(scopeKey) : null;
2845 + if (event.shiftKey && event.key === "Enter") {
2846 + if (!project) return;
2847 + event.preventDefault();
2848 + toggleProjectScopeKey(project.projectKey);
2849 + return;
2850 + }
2851 + if (
2852 + event.key !== "ContextMenu" &&
2853 + !(event.shiftKey && event.key === "F10")
2854 + ) {
2855 + return;
2856 + }
2857 if (project) handleProjectSettings(event, project);
2858 }}
2859 onChange={(event) =>
@@ -2800,23 +2864,31 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2864 }
2865 />
2866 <ComboboxEmpty>No matching projects.</ComboboxEmpty>
2803 - <ComboboxList>
2867 + <ComboboxList aria-multiselectable>
2868 {(item: (typeof projectScopeItems)[number]) => {
2869 const project = projectGroupByScopeKey.get(item.value) ?? null;
2870 + const isSelected = project
2871 + ? projectScopeKeys.includes(item.value)
2872 + : projectScopeKeys.length === 0;
2873 return (
2874 <ComboboxItem
2875 key={item.value}
2876 hideIndicator
2877 value={item}
2878 + aria-selected={isSelected}
2879 + // The icon badge marks selection; Base UI's single value would shade one row.
2880 + data-selected={undefined}
2881 onContextMenu={(event) => {
2882 if (project) handleProjectSettings(event, project);
2883 }}
2884 >
2815 - {project ? (
2816 - <ProjectFavicon project={project} className="size-4 shrink-0" />
2817 - ) : (
2818 - <FolderIcon className="size-4 shrink-0" />
2819 - )}
2885 + <ProjectScopeRowIcon isSelected={isSelected}>
2886 + {project ? (
2887 + <ProjectFavicon project={project} className="size-4 shrink-0" />
2888 + ) : (
2889 + <FolderIcon className="size-4 shrink-0" />
2890 + )}
2891 + </ProjectScopeRowIcon>
2892 <span className="min-w-0 flex-1 truncate text-sm">{item.label}</span>
2893 {project && showProjectEnvironments ? (
2894 <ProjectEnvironmentBadge
@@ -3261,8 +3333,10 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
3333 Add project
3334 </button>
3335 </>
3264 - ) : scopedProjectGroup ? (
3265 - `No threads in ${scopedProjectGroup.displayName} yet`
3336 + ) : scopedProjectGroups.length > 1 ? (
3337 + "No threads in these projects yet"
3338 + ) : scopedProjectGroups[0] ? (
3339 + `No threads in ${scopedProjectGroups[0].displayName} yet`
3340 ) : (
3341 "No threads yet"
3342 )}
apps/web/src/sidebarProjectGrouping.ts
+11
@@ -84,6 +84,17 @@ export function resolveSidebarProjectScopeKey(input: {
84 return group?.projectKey ?? (input.canClearMissingScope ? null : input.key);
85 }
86
87 +export function resolveSidebarProjectScopeKeys(input: {
88 + readonly groups: ReadonlyArray<SidebarProjectSnapshot>;
89 + readonly keys: ReadonlyArray<string>;
90 + readonly settings?: ProjectGroupingSettings;
91 + readonly canClearMissingScope?: boolean;
92 +}): string[] {
93 + return [
94 + ...new Set(input.keys.flatMap((key) => resolveSidebarProjectScopeKey({ ...input, key }) ?? [])),
95 + ];
96 +}
97 +
98 export function buildPhysicalToLogicalProjectKeyMap(input: {
99 projects: ReadonlyArray<Project>;
100 settings: ProjectGroupingSettings;
apps/web/src/uiStateStore.test.ts
+23 -6
@@ -19,7 +19,7 @@ function makeUiState(overrides: Partial<UiState> = {}): UiState {
19 return {
20 projectExpandedById: {},
21 projectOrder: [],
22 - sidebarProjectScopeKey: null,
22 + sidebarProjectScopeKeys: [],
23 threadLastVisitedAtById: {},
24 threadChangedFilesExpandedById: {},
25 defaultAdvertisedEndpointKey: null,
@@ -125,7 +125,7 @@ describe("parsePersistedState", () => {
125 "environment:thread-1": "2026-02-25T12:35:00.000Z",
126 },
127 defaultAdvertisedEndpointKey: "desktop-core:lan:http",
128 - sidebarProjectScopeKey: null,
128 + sidebarProjectScopeKeys: [],
129 pullRequestMergeMethod: "merge",
130 threadChangedFilesExpandedById: {
131 "environment:thread-1": {
@@ -230,6 +230,7 @@ describe("uiStateStore persistence", () => {
230 "environment:thread-1": "2026-02-25T12:35:00.000Z",
231 },
232 defaultAdvertisedEndpointKey: "desktop-core:lan:http",
233 + sidebarProjectScopeKeys: [],
234 sidebarProjectScopeKey: null,
235 threadChangedFilesExpansionVersion: 2,
236 threadChangedFilesExpandedById: {
@@ -246,14 +247,30 @@ describe("uiStateStore persistence", () => {
247 });
248
249 it("restores the sidebar project scope across reloads", () => {
249 - persistState(makeUiState({ sidebarProjectScopeKey: "github.com/pingdotgg/t3code" }));
250 + const keys = ["github.com/pingdotgg/t3code", "github.com/pingdotgg/uploadthing"];
251 + persistState(makeUiState({ sidebarProjectScopeKeys: keys }));
252
253 const persisted = JSON.parse(
254 localStorageStub.getItem(PERSISTED_STATE_KEY) ?? "{}",
255 ) as PersistedUiState;
256
255 - expect(parsePersistedState(persisted).sidebarProjectScopeKey).toBe(
256 - "github.com/pingdotgg/t3code",
257 - );
257 + expect(parsePersistedState(persisted).sidebarProjectScopeKeys).toEqual(keys);
258 + });
259 +
260 + it("keeps a single-project scope readable by older clients", () => {
261 + persistState(makeUiState({ sidebarProjectScopeKeys: ["github.com/pingdotgg/t3code"] }));
262 +
263 + const persisted = JSON.parse(
264 + localStorageStub.getItem(PERSISTED_STATE_KEY) ?? "{}",
265 + ) as PersistedUiState;
266 +
267 + expect(persisted.sidebarProjectScopeKey).toBe("github.com/pingdotgg/t3code");
268 + });
269 +
270 + it("restores a single-project scope saved before multi-project filtering", () => {
271 + expect(
272 + parsePersistedState({ sidebarProjectScopeKey: "github.com/pingdotgg/t3code" })
273 + .sidebarProjectScopeKeys,
274 + ).toEqual(["github.com/pingdotgg/t3code"]);
275 });
276 });
apps/web/src/uiStateStore.ts
+22 -11
@@ -27,6 +27,7 @@ export interface PersistedUiState {
27 projectOrderCwds?: string[];
28 defaultAdvertisedEndpointKey?: string | null;
29 sidebarProjectScopeKey?: string | null;
30 + sidebarProjectScopeKeys?: string[];
31 threadChangedFilesExpansionVersion?: number;
32 threadChangedFilesExpandedById?: Record<string, Record<string, boolean>>;
33 pullRequestMergeMethod?: string;
@@ -35,7 +36,7 @@ export interface PersistedUiState {
36 export interface UiProjectState {
37 projectExpandedById: Record<string, boolean>;
38 projectOrder: string[];
38 - sidebarProjectScopeKey: string | null;
39 + sidebarProjectScopeKeys: string[];
40 }
41
42 export interface UiThreadState {
@@ -57,7 +58,7 @@ export interface UiState
58 const initialState: UiState = {
59 projectExpandedById: {},
60 projectOrder: [],
60 - sidebarProjectScopeKey: null,
61 + sidebarProjectScopeKeys: [],
62 threadLastVisitedAtById: {},
63 threadChangedFilesExpandedById: {},
64 defaultAdvertisedEndpointKey: null,
@@ -150,7 +151,9 @@ export function parsePersistedState(parsed: PersistedUiState): UiState {
151 ? sanitizePersistedThreadChangedFilesExpanded(parsed.threadChangedFilesExpandedById)
152 : {},
153 defaultAdvertisedEndpointKey: sanitizeOptionalKey(parsed.defaultAdvertisedEndpointKey),
153 - sidebarProjectScopeKey: sanitizeOptionalKey(parsed.sidebarProjectScopeKey),
154 + sidebarProjectScopeKeys: sanitizeStringArray(
155 + parsed.sidebarProjectScopeKeys ?? [parsed.sidebarProjectScopeKey],
156 + ),
157 pullRequestMergeMethod: isPullRequestMergeMethod(parsed.pullRequestMergeMethod)
158 ? parsed.pullRequestMergeMethod
159 : initialState.pullRequestMergeMethod,
@@ -224,7 +227,12 @@ export function persistState(state: UiState): void {
227 projectOrder: state.projectOrder,
228 threadLastVisitedAtById: state.threadLastVisitedAtById,
229 defaultAdvertisedEndpointKey: state.defaultAdvertisedEndpointKey,
227 - sidebarProjectScopeKey: state.sidebarProjectScopeKey,
230 + sidebarProjectScopeKeys: state.sidebarProjectScopeKeys,
231 + // Older clients read only this field.
232 + sidebarProjectScopeKey:
233 + state.sidebarProjectScopeKeys.length === 1
234 + ? (state.sidebarProjectScopeKeys[0] ?? null)
235 + : null,
236 threadChangedFilesExpansionVersion: THREAD_CHANGED_FILES_EXPANSION_VERSION,
237 threadChangedFilesExpandedById: state.threadChangedFilesExpandedById,
238 pullRequestMergeMethod: state.pullRequestMergeMethod,
@@ -323,14 +331,17 @@ function setDefaultAdvertisedEndpointKey(state: UiState, key: string | null): Ui
331 };
332 }
333
326 -function setSidebarProjectScopeKey(state: UiState, projectKey: string | null): UiState {
327 - const nextKey = sanitizeOptionalKey(projectKey);
328 - if (state.sidebarProjectScopeKey === nextKey) {
334 +function setSidebarProjectScopeKeys(state: UiState, projectKeys: readonly string[]): UiState {
335 + const nextKeys = sanitizeStringArray(projectKeys);
336 + if (
337 + nextKeys.length === state.sidebarProjectScopeKeys.length &&
338 + nextKeys.every((key, index) => key === state.sidebarProjectScopeKeys[index])
339 + ) {
340 return state;
341 }
342 return {
343 ...state,
333 - sidebarProjectScopeKey: nextKey,
344 + sidebarProjectScopeKeys: nextKeys,
345 };
346 }
347
@@ -422,7 +433,7 @@ interface UiStateStore extends UiState {
433 markThreadUnread: (threadId: string, latestTurnCompletedAt: string | null | undefined) => void;
434 setThreadChangedFilesExpanded: (threadId: string, turnId: string, expanded: boolean) => void;
435 setDefaultAdvertisedEndpointKey: (key: string | null) => void;
425 - setSidebarProjectScopeKey: (projectKey: string | null) => void;
436 + setSidebarProjectScopeKeys: (projectKeys: readonly string[]) => void;
437 setPullRequestMergeMethod: (method: PullRequestMergeMethod) => void;
438 setProjectExpanded: (projectIds: string | readonly string[], expanded: boolean) => void;
439 reorderProjects: (
@@ -442,8 +453,8 @@ export const useUiStateStore = create<UiStateStore>((set) => ({
453 set((state) => setThreadChangedFilesExpanded(state, threadId, turnId, expanded)),
454 setDefaultAdvertisedEndpointKey: (key) =>
455 set((state) => setDefaultAdvertisedEndpointKey(state, key)),
445 - setSidebarProjectScopeKey: (projectKey) =>
446 - set((state) => setSidebarProjectScopeKey(state, projectKey)),
456 + setSidebarProjectScopeKeys: (projectKeys) =>
457 + set((state) => setSidebarProjectScopeKeys(state, projectKeys)),
458 setPullRequestMergeMethod: (method) => set((state) => setPullRequestMergeMethod(state, method)),
459 setProjectExpanded: (projectIds, expanded) =>
460 set((state) => setProjectExpanded(state, projectIds, expanded)),