| author | |
| committer | |
| log | 9385314d26aba97d1fed1e05066e4562dbdf56bc |
| tree | 35c11e286f0f97eca263b6be4e8e3ba082be7c4d |
| parent | a3f292770ed66b6521e7b3d92de92b1be0c463d7 |
| signature | Signed by PGP key B5690EEEBB952194 |
6 files changed, 237 insertions(+), 17 deletions(-)
apps/web/src/components/ChatView.tsx+23-2| ... | ... | @@ -172,6 +172,7 @@ const IMAGE_ONLY_BOOTSTRAP_PROMPT = |
| 172 | 172 | const EMPTY_ACTIVITIES: OrchestrationThreadActivity[] = []; |
| 173 | 173 | const EMPTY_PROPOSED_PLANS: Thread["proposedPlans"] = []; |
| 174 | 174 | const EMPTY_PROVIDERS: ServerProvider[] = []; |
| 175 | const EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID: Record<string, boolean> = {}; | |
| 175 | 176 | const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {}; |
| 176 | 177 | |
| 177 | 178 | type ThreadPlanCatalogEntry = Pick<Thread, "id" | "proposedPlans">; |
| ... | ... | @@ -574,6 +575,7 @@ export default function ChatView(props: ChatViewProps) { |
| 574 | 575 | () => scopeThreadRef(environmentId, threadId), |
| 575 | 576 | [environmentId, threadId], |
| 576 | 577 | ); |
| 578 | const routeThreadKey = useMemo(() => scopedThreadKey(routeThreadRef), [routeThreadRef]); | |
| 577 | 579 | const composerDraftTarget: ScopedThreadRef | DraftId = |
| 578 | 580 | routeKind === "server" ? routeThreadRef : props.draftId; |
| 579 | 581 | const serverThread = useStore( |
| ... | ... | @@ -584,10 +586,17 @@ export default function ChatView(props: ChatViewProps) { |
| 584 | 586 | ); |
| 585 | 587 | const setStoreThreadError = useStore((store) => store.setError); |
| 586 | 588 | const markThreadVisited = useUiStateStore((store) => store.markThreadVisited); |
| 589 | const setThreadChangedFilesExpanded = useUiStateStore( | |
| 590 | (store) => store.setThreadChangedFilesExpanded, | |
| 591 | ); | |
| 587 | 592 | const activeThreadLastVisitedAt = useUiStateStore((store) => |
| 593 | routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined, | |
| 594 | ); | |
| 595 | const changedFilesExpandedByTurnId = useUiStateStore((store) => | |
| 588 | 596 | routeKind === "server" |
| 589 | ? store.threadLastVisitedAtById[scopedThreadKey(scopeThreadRef(environmentId, threadId))] | |
| 590 | : undefined, | |
| 597 | ? (store.threadChangedFilesExpandedById[routeThreadKey] ?? | |
| 598 | EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID) | |
| 599 | : EMPTY_CHANGED_FILES_EXPANDED_BY_TURN_ID, | |
| 591 | 600 | ); |
| 592 | 601 | const settings = useSettings(); |
| 593 | 602 | const setStickyComposerModelSelection = useComposerDraftStore( |
| ... | ... | @@ -981,6 +990,16 @@ export default function ChatView(props: ChatViewProps) { |
| 981 | 990 | [openOrReuseProjectDraftThread], |
| 982 | 991 | ); |
| 983 | 992 | |
| 993 | const handleSetChangedFilesExpanded = useCallback( | |
| 994 | (turnId: TurnId, expanded: boolean) => { | |
| 995 | if (routeKind !== "server") { | |
| 996 | return; | |
| 997 | } | |
| 998 | setThreadChangedFilesExpanded(routeThreadKey, turnId, expanded); | |
| 999 | }, | |
| 1000 | [routeKind, routeThreadKey, setThreadChangedFilesExpanded], | |
| 1001 | ); | |
| 1002 | ||
| 984 | 1003 | useEffect(() => { |
| 985 | 1004 | if (!serverThread?.id) return; |
| 986 | 1005 | if (!latestTurnSettled) return; |
| ... | ... | @@ -3337,6 +3356,8 @@ export default function ChatView(props: ChatViewProps) { |
| 3337 | 3356 | activeThreadEnvironmentId={activeThread.environmentId} |
| 3338 | 3357 | expandedWorkGroups={expandedWorkGroups} |
| 3339 | 3358 | onToggleWorkGroup={onToggleWorkGroup} |
| 3359 | changedFilesExpandedByTurnId={changedFilesExpandedByTurnId} | |
| 3360 | onSetChangedFilesExpanded={handleSetChangedFilesExpanded} | |
| 3340 | 3361 | onOpenTurnDiff={onOpenTurnDiff} |
| 3341 | 3362 | revertTurnCountByUserMessageId={revertTurnCountByUserMessageId} |
| 3342 | 3363 | onRevertUserMessage={onRevertUserMessage} |
apps/web/src/components/chat/MessagesTimeline.test.tsx+4| ... | ... | @@ -82,6 +82,8 @@ describe("MessagesTimeline", () => { |
| 82 | 82 | nowIso="2026-03-17T19:12:30.000Z" |
| 83 | 83 | expandedWorkGroups={{}} |
| 84 | 84 | onToggleWorkGroup={() => {}} |
| 85 | changedFilesExpandedByTurnId={{}} | |
| 86 | onSetChangedFilesExpanded={() => {}} | |
| 85 | 87 | onOpenTurnDiff={() => {}} |
| 86 | 88 | revertTurnCountByUserMessageId={new Map()} |
| 87 | 89 | onRevertUserMessage={() => {}} |
| ... | ... | @@ -128,6 +130,8 @@ describe("MessagesTimeline", () => { |
| 128 | 130 | nowIso="2026-03-17T19:12:30.000Z" |
| 129 | 131 | expandedWorkGroups={{}} |
| 130 | 132 | onToggleWorkGroup={() => {}} |
| 133 | changedFilesExpandedByTurnId={{}} | |
| 134 | onSetChangedFilesExpanded={() => {}} | |
| 131 | 135 | onOpenTurnDiff={() => {}} |
| 132 | 136 | revertTurnCountByUserMessageId={new Map()} |
| 133 | 137 | onRevertUserMessage={() => {}} |
apps/web/src/components/chat/MessagesTimeline.tsx+8-11| ... | ... | @@ -77,6 +77,8 @@ interface MessagesTimelineProps { |
| 77 | 77 | nowIso: string; |
| 78 | 78 | expandedWorkGroups: Record<string, boolean>; |
| 79 | 79 | onToggleWorkGroup: (groupId: string) => void; |
| 80 | changedFilesExpandedByTurnId: Record<string, boolean>; | |
| 81 | onSetChangedFilesExpanded: (turnId: TurnId, expanded: boolean) => void; | |
| 80 | 82 | onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void; |
| 81 | 83 | revertTurnCountByUserMessageId: Map<MessageId, number>; |
| 82 | 84 | onRevertUserMessage: (messageId: MessageId) => void; |
| ... | ... | @@ -113,6 +115,8 @@ export const MessagesTimeline = memo(function MessagesTimeline({ |
| 113 | 115 | nowIso, |
| 114 | 116 | expandedWorkGroups, |
| 115 | 117 | onToggleWorkGroup, |
| 118 | changedFilesExpandedByTurnId, | |
| 119 | onSetChangedFilesExpanded, | |
| 116 | 120 | onOpenTurnDiff, |
| 117 | 121 | revertTurnCountByUserMessageId, |
| 118 | 122 | onRevertUserMessage, |
| ... | ... | @@ -296,15 +300,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({ |
| 296 | 300 | |
| 297 | 301 | const virtualRows = rowVirtualizer.getVirtualItems(); |
| 298 | 302 | const nonVirtualizedRows = rows.slice(virtualizedRowCount); |
| 299 | const [allDirectoriesExpandedByTurnId, setAllDirectoriesExpandedByTurnId] = useState< | |
| 300 | Record<string, boolean> | |
| 301 | >({}); | |
| 302 | const onToggleAllDirectories = useCallback((turnId: TurnId) => { | |
| 303 | setAllDirectoriesExpandedByTurnId((current) => ({ | |
| 304 | ...current, | |
| 305 | [turnId]: !(current[turnId] ?? true), | |
| 306 | })); | |
| 307 | }, []); | |
| 308 | 303 | |
| 309 | 304 | const renderRowContent = (row: TimelineRow) => ( |
| 310 | 305 | <div |
| ... | ... | @@ -466,7 +461,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({ |
| 466 | 461 | const summaryStat = summarizeTurnDiffStats(checkpointFiles); |
| 467 | 462 | const changedFileCountLabel = String(checkpointFiles.length); |
| 468 | 463 | const allDirectoriesExpanded = |
| 469 | allDirectoriesExpandedByTurnId[turnSummary.turnId] ?? true; | |
| 464 | changedFilesExpandedByTurnId[turnSummary.turnId] ?? true; | |
| 470 | 465 | return ( |
| 471 | 466 | <div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5"> |
| 472 | 467 | <div className="mb-1.5 flex items-center justify-between gap-2"> |
| ... | ... | @@ -488,7 +483,9 @@ export const MessagesTimeline = memo(function MessagesTimeline({ |
| 488 | 483 | size="xs" |
| 489 | 484 | variant="outline" |
| 490 | 485 | data-scroll-anchor-ignore |
| 491 | onClick={() => onToggleAllDirectories(turnSummary.turnId)} | |
| 486 | onClick={() => | |
| 487 | onSetChangedFilesExpanded(turnSummary.turnId, !allDirectoriesExpanded) | |
| 488 | } | |
| 492 | 489 | > |
| 493 | 490 | {allDirectoriesExpanded ? "Collapse all" : "Expand all"} |
| 494 | 491 | </Button> |
apps/web/src/components/chat/MessagesTimeline.virtualization.browser.tsx+17| ... | ... | @@ -61,6 +61,9 @@ function MessagesTimelineBrowserHarness( |
| 61 | 61 | const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>( |
| 62 | 62 | () => props.expandedWorkGroups, |
| 63 | 63 | ); |
| 64 | const [changedFilesExpandedByTurnId, setChangedFilesExpandedByTurnId] = useState< | |
| 65 | Record<string, boolean> | |
| 66 | >(() => props.changedFilesExpandedByTurnId); | |
| 64 | 67 | const handleToggleWorkGroup = useCallback( |
| 65 | 68 | (groupId: string) => { |
| 66 | 69 | setExpandedWorkGroups((current) => ({ |
| ... | ... | @@ -71,6 +74,16 @@ function MessagesTimelineBrowserHarness( |
| 71 | 74 | }, |
| 72 | 75 | [props], |
| 73 | 76 | ); |
| 77 | const handleSetChangedFilesExpanded = useCallback( | |
| 78 | (turnId: TurnId, expanded: boolean) => { | |
| 79 | setChangedFilesExpandedByTurnId((current) => ({ | |
| 80 | ...current, | |
| 81 | [turnId]: expanded, | |
| 82 | })); | |
| 83 | props.onSetChangedFilesExpanded(turnId, expanded); | |
| 84 | }, | |
| 85 | [props], | |
| 86 | ); | |
| 74 | 87 | |
| 75 | 88 | return ( |
| 76 | 89 | <div |
| ... | ... | @@ -84,6 +97,8 @@ function MessagesTimelineBrowserHarness( |
| 84 | 97 | scrollContainer={scrollContainer} |
| 85 | 98 | expandedWorkGroups={expandedWorkGroups} |
| 86 | 99 | onToggleWorkGroup={handleToggleWorkGroup} |
| 100 | changedFilesExpandedByTurnId={changedFilesExpandedByTurnId} | |
| 101 | onSetChangedFilesExpanded={handleSetChangedFilesExpanded} | |
| 87 | 102 | /> |
| 88 | 103 | </div> |
| 89 | 104 | ); |
| ... | ... | @@ -168,6 +183,8 @@ function createBaseTimelineProps(input: { |
| 168 | 183 | nowIso: isoAt(10_000), |
| 169 | 184 | expandedWorkGroups: input.expandedWorkGroups ?? {}, |
| 170 | 185 | onToggleWorkGroup: () => {}, |
| 186 | changedFilesExpandedByTurnId: {}, | |
| 187 | onSetChangedFilesExpanded: () => {}, | |
| 171 | 188 | onOpenTurnDiff: () => {}, |
| 172 | 189 | revertTurnCountByUserMessageId: new Map(), |
| 173 | 190 | onRevertUserMessage: () => {}, |
apps/web/src/uiStateStore.test.ts+49| ... | ... | @@ -6,6 +6,7 @@ import { |
| 6 | 6 | markThreadUnread, |
| 7 | 7 | reorderProjects, |
| 8 | 8 | setProjectExpanded, |
| 9 | setThreadChangedFilesExpanded, | |
| 9 | 10 | syncProjects, |
| 10 | 11 | syncThreads, |
| 11 | 12 | type UiState, |
| ... | ... | @@ -16,6 +17,7 @@ function makeUiState(overrides: Partial<UiState> = {}): UiState { |
| 16 | 17 | projectExpandedById: {}, |
| 17 | 18 | projectOrder: [], |
| 18 | 19 | threadLastVisitedAtById: {}, |
| 20 | threadChangedFilesExpandedById: {}, | |
| 19 | 21 | ...overrides, |
| 20 | 22 | }; |
| 21 | 23 | } |
| ... | ... | @@ -137,6 +139,14 @@ describe("uiStateStore pure functions", () => { |
| 137 | 139 | [thread1]: "2026-02-25T12:35:00.000Z", |
| 138 | 140 | [thread2]: "2026-02-25T12:36:00.000Z", |
| 139 | 141 | }, |
| 142 | threadChangedFilesExpandedById: { | |
| 143 | [thread1]: { | |
| 144 | "turn-1": false, | |
| 145 | }, | |
| 146 | [thread2]: { | |
| 147 | "turn-2": false, | |
| 148 | }, | |
| 149 | }, | |
| 140 | 150 | }); |
| 141 | 151 | |
| 142 | 152 | const next = syncThreads(initialState, [{ key: thread1 }]); |
| ... | ... | @@ -144,6 +154,11 @@ describe("uiStateStore pure functions", () => { |
| 144 | 154 | expect(next.threadLastVisitedAtById).toEqual({ |
| 145 | 155 | [thread1]: "2026-02-25T12:35:00.000Z", |
| 146 | 156 | }); |
| 157 | expect(next.threadChangedFilesExpandedById).toEqual({ | |
| 158 | [thread1]: { | |
| 159 | "turn-1": false, | |
| 160 | }, | |
| 161 | }); | |
| 147 | 162 | }); |
| 148 | 163 | |
| 149 | 164 | it("syncThreads seeds visit state for unseen snapshot threads", () => { |
| ... | ... | @@ -183,10 +198,44 @@ describe("uiStateStore pure functions", () => { |
| 183 | 198 | threadLastVisitedAtById: { |
| 184 | 199 | [thread1]: "2026-02-25T12:35:00.000Z", |
| 185 | 200 | }, |
| 201 | threadChangedFilesExpandedById: { | |
| 202 | [thread1]: { | |
| 203 | "turn-1": false, | |
| 204 | }, | |
| 205 | }, | |
| 186 | 206 | }); |
| 187 | 207 | |
| 188 | 208 | const next = clearThreadUi(initialState, thread1); |
| 189 | 209 | |
| 190 | 210 | expect(next.threadLastVisitedAtById).toEqual({}); |
| 211 | expect(next.threadChangedFilesExpandedById).toEqual({}); | |
| 212 | }); | |
| 213 | ||
| 214 | it("setThreadChangedFilesExpanded stores collapsed turns per thread", () => { | |
| 215 | const thread1 = ThreadId.make("thread-1"); | |
| 216 | const initialState = makeUiState(); | |
| 217 | ||
| 218 | const next = setThreadChangedFilesExpanded(initialState, thread1, "turn-1", false); | |
| 219 | ||
| 220 | expect(next.threadChangedFilesExpandedById).toEqual({ | |
| 221 | [thread1]: { | |
| 222 | "turn-1": false, | |
| 223 | }, | |
| 224 | }); | |
| 225 | }); | |
| 226 | ||
| 227 | it("setThreadChangedFilesExpanded removes thread overrides when expanded again", () => { | |
| 228 | const thread1 = ThreadId.make("thread-1"); | |
| 229 | const initialState = makeUiState({ | |
| 230 | threadChangedFilesExpandedById: { | |
| 231 | [thread1]: { | |
| 232 | "turn-1": false, | |
| 233 | }, | |
| 234 | }, | |
| 235 | }); | |
| 236 | ||
| 237 | const next = setThreadChangedFilesExpanded(initialState, thread1, "turn-1", true); | |
| 238 | ||
| 239 | expect(next.threadChangedFilesExpandedById).toEqual({}); | |
| 191 | 240 | }); |
| 192 | 241 | }); |
apps/web/src/uiStateStore.ts+136-4| ... | ... | @@ -18,6 +18,7 @@ const LEGACY_PERSISTED_STATE_KEYS = [ |
| 18 | 18 | interface PersistedUiState { |
| 19 | 19 | expandedProjectCwds?: string[]; |
| 20 | 20 | projectOrderCwds?: string[]; |
| 21 | threadChangedFilesExpandedById?: Record<string, Record<string, boolean>>; | |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | export interface UiProjectState { |
| ... | ... | @@ -27,6 +28,7 @@ export interface UiProjectState { |
| 27 | 28 | |
| 28 | 29 | export interface UiThreadState { |
| 29 | 30 | threadLastVisitedAtById: Record<string, string>; |
| 31 | threadChangedFilesExpandedById: Record<string, Record<string, boolean>>; | |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | export interface UiState extends UiProjectState, UiThreadState {} |
| ... | ... | @@ -45,6 +47,7 @@ const initialState: UiState = { |
| 45 | 47 | projectExpandedById: {}, |
| 46 | 48 | projectOrder: [], |
| 47 | 49 | threadLastVisitedAtById: {}, |
| 50 | threadChangedFilesExpandedById: {}, | |
| 48 | 51 | }; |
| 49 | 52 | |
| 50 | 53 | const persistedExpandedProjectCwds = new Set<string>(); |
| ... | ... | @@ -69,13 +72,47 @@ function readPersistedState(): UiState { |
| 69 | 72 | } |
| 70 | 73 | return initialState; |
| 71 | 74 | } |
| 72 | hydratePersistedProjectState(JSON.parse(raw) as PersistedUiState); | |
| 73 | return initialState; | |
| 75 | const parsed = JSON.parse(raw) as PersistedUiState; | |
| 76 | hydratePersistedProjectState(parsed); | |
| 77 | return { | |
| 78 | ...initialState, | |
| 79 | threadChangedFilesExpandedById: sanitizePersistedThreadChangedFilesExpanded( | |
| 80 | parsed.threadChangedFilesExpandedById, | |
| 81 | ), | |
| 82 | }; | |
| 74 | 83 | } catch { |
| 75 | 84 | return initialState; |
| 76 | 85 | } |
| 77 | 86 | } |
| 78 | 87 | |
| 88 | function sanitizePersistedThreadChangedFilesExpanded( | |
| 89 | value: PersistedUiState["threadChangedFilesExpandedById"], | |
| 90 | ): Record<string, Record<string, boolean>> { | |
| 91 | if (!value || typeof value !== "object") { | |
| 92 | return {}; | |
| 93 | } | |
| 94 | ||
| 95 | const nextState: Record<string, Record<string, boolean>> = {}; | |
| 96 | for (const [threadId, turns] of Object.entries(value)) { | |
| 97 | if (!threadId || !turns || typeof turns !== "object") { | |
| 98 | continue; | |
| 99 | } | |
| 100 | ||
| 101 | const nextTurns: Record<string, boolean> = {}; | |
| 102 | for (const [turnId, expanded] of Object.entries(turns)) { | |
| 103 | if (turnId && typeof expanded === "boolean" && expanded === false) { | |
| 104 | nextTurns[turnId] = false; | |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 108 | if (Object.keys(nextTurns).length > 0) { | |
| 109 | nextState[threadId] = nextTurns; | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | return nextState; | |
| 114 | } | |
| 115 | ||
| 79 | 116 | function hydratePersistedProjectState(parsed: PersistedUiState): void { |
| 80 | 117 | persistedExpandedProjectCwds.clear(); |
| 81 | 118 | persistedProjectOrderCwds.length = 0; |
| ... | ... | @@ -106,11 +143,20 @@ function persistState(state: UiState): void { |
| 106 | 143 | const cwd = currentProjectCwdById.get(projectId); |
| 107 | 144 | return cwd ? [cwd] : []; |
| 108 | 145 | }); |
| 146 | const threadChangedFilesExpandedById = Object.fromEntries( | |
| 147 | Object.entries(state.threadChangedFilesExpandedById).flatMap(([threadId, turns]) => { | |
| 148 | const nextTurns = Object.fromEntries( | |
| 149 | Object.entries(turns).filter(([, expanded]) => expanded === false), | |
| 150 | ); | |
| 151 | return Object.keys(nextTurns).length > 0 ? [[threadId, nextTurns]] : []; | |
| 152 | }), | |
| 153 | ); | |
| 109 | 154 | window.localStorage.setItem( |
| 110 | 155 | PERSISTED_STATE_KEY, |
| 111 | 156 | JSON.stringify({ |
| 112 | 157 | expandedProjectCwds, |
| 113 | 158 | projectOrderCwds, |
| 159 | threadChangedFilesExpandedById, | |
| 114 | 160 | } satisfies PersistedUiState), |
| 115 | 161 | ); |
| 116 | 162 | if (!legacyKeysCleanedUp) { |
| ... | ... | @@ -146,6 +192,23 @@ function projectOrdersEqual(left: readonly string[], right: readonly string[]): |
| 146 | 192 | ); |
| 147 | 193 | } |
| 148 | 194 | |
| 195 | function nestedBooleanRecordsEqual( | |
| 196 | left: Record<string, Record<string, boolean>>, | |
| 197 | right: Record<string, Record<string, boolean>>, | |
| 198 | ): boolean { | |
| 199 | const leftEntries = Object.entries(left); | |
| 200 | const rightEntries = Object.entries(right); | |
| 201 | if (leftEntries.length !== rightEntries.length) { | |
| 202 | return false; | |
| 203 | } | |
| 204 | for (const [key, value] of leftEntries) { | |
| 205 | if (!(key in right) || !recordsEqual(value, right[key]!)) { | |
| 206 | return false; | |
| 207 | } | |
| 208 | } | |
| 209 | return true; | |
| 210 | } | |
| 211 | ||
| 149 | 212 | export function syncProjects(state: UiState, projects: readonly SyncProjectInput[]): UiState { |
| 150 | 213 | const previousProjectCwdById = new Map(currentProjectCwdById); |
| 151 | 214 | const previousProjectIdByCwd = new Map( |
| ... | ... | @@ -260,12 +323,24 @@ export function syncThreads(state: UiState, threads: readonly SyncThreadInput[]) |
| 260 | 323 | nextThreadLastVisitedAtById[thread.key] = thread.seedVisitedAt; |
| 261 | 324 | } |
| 262 | 325 | } |
| 263 | if (recordsEqual(state.threadLastVisitedAtById, nextThreadLastVisitedAtById)) { | |
| 326 | const nextThreadChangedFilesExpandedById = Object.fromEntries( | |
| 327 | Object.entries(state.threadChangedFilesExpandedById).filter(([threadId]) => | |
| 328 | retainedThreadIds.has(threadId), | |
| 329 | ), | |
| 330 | ); | |
| 331 | if ( | |
| 332 | recordsEqual(state.threadLastVisitedAtById, nextThreadLastVisitedAtById) && | |
| 333 | nestedBooleanRecordsEqual( | |
| 334 | state.threadChangedFilesExpandedById, | |
| 335 | nextThreadChangedFilesExpandedById, | |
| 336 | ) | |
| 337 | ) { | |
| 264 | 338 | return state; |
| 265 | 339 | } |
| 266 | 340 | return { |
| 267 | 341 | ...state, |
| 268 | 342 | threadLastVisitedAtById: nextThreadLastVisitedAtById, |
| 343 | threadChangedFilesExpandedById: nextThreadChangedFilesExpandedById, | |
| 269 | 344 | }; |
| 270 | 345 | } |
| 271 | 346 | |
| ... | ... | @@ -316,14 +391,68 @@ export function markThreadUnread( |
| 316 | 391 | } |
| 317 | 392 | |
| 318 | 393 | export function clearThreadUi(state: UiState, threadId: string): UiState { |
| 319 | if (!(threadId in state.threadLastVisitedAtById)) { | |
| 394 | const hasVisitedState = threadId in state.threadLastVisitedAtById; | |
| 395 | const hasChangedFilesState = threadId in state.threadChangedFilesExpandedById; | |
| 396 | if (!hasVisitedState && !hasChangedFilesState) { | |
| 320 | 397 | return state; |
| 321 | 398 | } |
| 322 | 399 | const nextThreadLastVisitedAtById = { ...state.threadLastVisitedAtById }; |
| 400 | const nextThreadChangedFilesExpandedById = { ...state.threadChangedFilesExpandedById }; | |
| 323 | 401 | delete nextThreadLastVisitedAtById[threadId]; |
| 402 | delete nextThreadChangedFilesExpandedById[threadId]; | |
| 324 | 403 | return { |
| 325 | 404 | ...state, |
| 326 | 405 | threadLastVisitedAtById: nextThreadLastVisitedAtById, |
| 406 | threadChangedFilesExpandedById: nextThreadChangedFilesExpandedById, | |
| 407 | }; | |
| 408 | } | |
| 409 | ||
| 410 | export function setThreadChangedFilesExpanded( | |
| 411 | state: UiState, | |
| 412 | threadId: string, | |
| 413 | turnId: string, | |
| 414 | expanded: boolean, | |
| 415 | ): UiState { | |
| 416 | const currentThreadState = state.threadChangedFilesExpandedById[threadId] ?? {}; | |
| 417 | const currentExpanded = currentThreadState[turnId] ?? true; | |
| 418 | if (currentExpanded === expanded) { | |
| 419 | return state; | |
| 420 | } | |
| 421 | ||
| 422 | if (expanded) { | |
| 423 | if (!(turnId in currentThreadState)) { | |
| 424 | return state; | |
| 425 | } | |
| 426 | ||
| 427 | const nextThreadState = { ...currentThreadState }; | |
| 428 | delete nextThreadState[turnId]; | |
| 429 | if (Object.keys(nextThreadState).length === 0) { | |
| 430 | const nextState = { ...state.threadChangedFilesExpandedById }; | |
| 431 | delete nextState[threadId]; | |
| 432 | return { | |
| 433 | ...state, | |
| 434 | threadChangedFilesExpandedById: nextState, | |
| 435 | }; | |
| 436 | } | |
| 437 | ||
| 438 | return { | |
| 439 | ...state, | |
| 440 | threadChangedFilesExpandedById: { | |
| 441 | ...state.threadChangedFilesExpandedById, | |
| 442 | [threadId]: nextThreadState, | |
| 443 | }, | |
| 444 | }; | |
| 445 | } | |
| 446 | ||
| 447 | return { | |
| 448 | ...state, | |
| 449 | threadChangedFilesExpandedById: { | |
| 450 | ...state.threadChangedFilesExpandedById, | |
| 451 | [threadId]: { | |
| 452 | ...currentThreadState, | |
| 453 | [turnId]: false, | |
| 454 | }, | |
| 455 | }, | |
| 327 | 456 | }; |
| 328 | 457 | } |
| 329 | 458 | |
| ... | ... | @@ -382,6 +511,7 @@ interface UiStateStore extends UiState { |
| 382 | 511 | markThreadVisited: (threadId: string, visitedAt?: string) => void; |
| 383 | 512 | markThreadUnread: (threadId: string, latestTurnCompletedAt: string | null | undefined) => void; |
| 384 | 513 | clearThreadUi: (threadId: string) => void; |
| 514 | setThreadChangedFilesExpanded: (threadId: string, turnId: string, expanded: boolean) => void; | |
| 385 | 515 | toggleProject: (projectId: string) => void; |
| 386 | 516 | setProjectExpanded: (projectId: string, expanded: boolean) => void; |
| 387 | 517 | reorderProjects: (draggedProjectId: string, targetProjectId: string) => void; |
| ... | ... | @@ -396,6 +526,8 @@ export const useUiStateStore = create<UiStateStore>((set) => ({ |
| 396 | 526 | markThreadUnread: (threadId, latestTurnCompletedAt) => |
| 397 | 527 | set((state) => markThreadUnread(state, threadId, latestTurnCompletedAt)), |
| 398 | 528 | clearThreadUi: (threadId) => set((state) => clearThreadUi(state, threadId)), |
| 529 | setThreadChangedFilesExpanded: (threadId, turnId, expanded) => | |
| 530 | set((state) => setThreadChangedFilesExpanded(state, threadId, turnId, expanded)), | |
| 399 | 531 | toggleProject: (projectId) => set((state) => toggleProject(state, projectId)), |
| 400 | 532 | setProjectExpanded: (projectId, expanded) => |
| 401 | 533 | set((state) => setProjectExpanded(state, projectId, expanded)), |