Skip to content

Commit 6cc8104

Browse files
Merge pull request #325 from corbitsdev/cl-5351-iife-cleanup
Extract noisy JSX/statement IIFEs (CL-5351 slice C)
2 parents 8ecb2c9 + c326c4d commit 6cc8104

5 files changed

Lines changed: 265 additions & 209 deletions

File tree

src/tui/app.tsx

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ export type AppProps = {
235235
onFirstUserMessage?: () => void;
236236
};
237237

238+
// Center a selection in a fixed-height window over a copy-target list.
239+
// Returns the visible slice and the absolute index of its first item so
240+
// the caller can mark the selected row without re-scanning the full list.
241+
function windowedCopyTargets(
242+
items: readonly CopyTarget[],
243+
selectedIndex: number,
244+
windowSize = 6,
245+
): { window: readonly CopyTarget[]; start: number } {
246+
const start = Math.max(
247+
0,
248+
Math.min(selectedIndex - Math.floor(windowSize / 2), Math.max(0, items.length - windowSize)),
249+
);
250+
return { window: items.slice(start, start + windowSize), start };
251+
}
252+
238253
export function App({
239254
eventEmitter,
240255
agent,
@@ -1074,6 +1089,40 @@ export function App({
10741089
);
10751090
}
10761091

1092+
// Work / Acceptance chrome: order flips by goal phase (implementing = Work on top).
1093+
const workBlock = hasActiveTasks(state.tasks) ? (
1094+
<Box flexDirection="column" marginTop={1} key="work">
1095+
<TaskView
1096+
tasks={state.tasks}
1097+
compact={!workExpanded}
1098+
title={goalActive ? "Work" : "Tasks"}
1099+
/>
1100+
</Box>
1101+
) : null;
1102+
const acceptBlock =
1103+
goalActive && goalSnapshot !== null ? (
1104+
<Box flexDirection="column" marginTop={1} key="accept">
1105+
<GoalView goal={goalSnapshot} compact={!showAcceptance} />
1106+
</Box>
1107+
) : null;
1108+
const workAcceptBlocks = workPrimary ? (
1109+
<>
1110+
{workBlock}
1111+
{acceptBlock}
1112+
</>
1113+
) : (
1114+
<>
1115+
{acceptBlock}
1116+
{workBlock}
1117+
</>
1118+
);
1119+
1120+
const copyModeSelection = copyModeIndex ?? 0;
1121+
const { window: copyModeWindow, start: copyModeWindowStart } = windowedCopyTargets(
1122+
copyTargetList,
1123+
copyModeSelection,
1124+
);
1125+
10771126
return (
10781127
<Box flexDirection="column" height={rows}>
10791128
<Box flexShrink={0} flexDirection="column">
@@ -1256,35 +1305,7 @@ export function App({
12561305
)}
12571306
{!taskFullScreenOpen && (
12581307
<Box flexShrink={0} flexDirection="column">
1259-
{(() => {
1260-
const workBlock = hasActiveTasks(state.tasks) ? (
1261-
<Box flexDirection="column" marginTop={1} key="work">
1262-
<TaskView
1263-
tasks={state.tasks}
1264-
compact={!workExpanded}
1265-
title={goalActive ? "Work" : "Tasks"}
1266-
/>
1267-
</Box>
1268-
) : null;
1269-
const acceptBlock =
1270-
goalActive && goalSnapshot !== null ? (
1271-
<Box flexDirection="column" marginTop={1} key="accept">
1272-
<GoalView goal={goalSnapshot} compact={!showAcceptance} />
1273-
</Box>
1274-
) : null;
1275-
// implementing: Work on top; planning/reviewing/completed: Acceptance on top
1276-
return workPrimary ? (
1277-
<>
1278-
{workBlock}
1279-
{acceptBlock}
1280-
</>
1281-
) : (
1282-
<>
1283-
{acceptBlock}
1284-
{workBlock}
1285-
</>
1286-
);
1287-
})()}
1308+
{workAcceptBlocks}
12881309
{agentsStripVisible ? (
12891310
<Box flexDirection="column" marginTop={1}>
12901311
<AgentsStrip
@@ -1317,20 +1338,15 @@ export function App({
13171338
{copyModeOpen && (
13181339
<Box flexDirection="column" marginTop={1} borderStyle="round" borderColor={color("brand")} paddingX={1}>
13191340
<Text color={color("brand")} bold>Copy — ↑/↓ select · y/⏎ copy · a copy all · esc cancel</Text>
1320-
{(() => {
1321-
const windowSize = 6;
1322-
const sel = copyModeIndex ?? 0;
1323-
const start = Math.max(0, Math.min(sel - Math.floor(windowSize / 2), Math.max(0, copyTargetList.length - windowSize)));
1324-
return copyTargetList.slice(start, start + windowSize).map((target, i) => {
1325-
const idx = start + i;
1326-
const selected = idx === sel;
1327-
return (
1328-
<Text key={target.id} color={selected ? color("text") : color("muted")} dimColor={!selected}>
1329-
{selected ? "› " : " "}{target.label}: {target.preview}
1330-
</Text>
1331-
);
1332-
});
1333-
})()}
1341+
{copyModeWindow.map((target, i) => {
1342+
const idx = copyModeWindowStart + i;
1343+
const selected = idx === copyModeSelection;
1344+
return (
1345+
<Text key={target.id} color={selected ? color("text") : color("muted")} dimColor={!selected}>
1346+
{selected ? "› " : " "}{target.label}: {target.preview}
1347+
</Text>
1348+
);
1349+
})}
13341350
</Box>
13351351
)}
13361352
{exitConfirmOpen ? (

src/tui/components/agent-modal.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ export function AgentModal({
789789
setFormError(null);
790790
});
791791

792-
const helpText = ((): string | null => {
792+
const helpText = ((): string | null => {
793793
switch (step) {
794794
case "provider":
795795
return "Up/Down navigate · Enter models · a add · e edit · x remove · t tiers · p profiles · Esc close";
@@ -814,6 +814,11 @@ export function AgentModal({
814814
}
815815
})();
816816
const helpLines = helpText !== null ? wrapHelpSegments(helpText.split(" · "), contentWidth) : [];
817+
const selectedProviderRow = providers[providerIndex];
818+
const showReauthHint =
819+
selectedProviderRow !== undefined &&
820+
(selectedProviderRow.codexProfile !== undefined || selectedProviderRow.xaiProfile !== undefined) &&
821+
unauthedProviders?.has(selectedProviderRow.name) === true;
817822

818823
return (
819824
<Box
@@ -863,15 +868,11 @@ export function AgentModal({
863868
</Box>
864869
);
865870
})}
866-
{(() => {
867-
const p = providers[providerIndex];
868-
const isUnauthed = p !== undefined && (p.codexProfile !== undefined || p.xaiProfile !== undefined) && unauthedProviders?.has(p.name) === true;
869-
return isUnauthed ? (
870-
<Box marginTop={1}>
871-
<Text color="red">Enter to re-authenticate</Text>
872-
</Box>
873-
) : null;
874-
})()}
871+
{showReauthHint ? (
872+
<Box marginTop={1}>
873+
<Text color="red">Enter to re-authenticate</Text>
874+
</Box>
875+
) : null}
875876
</Box>
876877
)}
877878

0 commit comments

Comments
 (0)