Skip to content
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
17 changes: 16 additions & 1 deletion frontend/src/components/AttentionFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ function AttentionCard({

// ─── Main component ────────────────────────────────────────────────────────

const DEFAULT_VISIBLE_COUNT = 5;

export function AttentionFeed() {
const { items, tier1Count, loading } = useAttentionFeed();
const navigate = useNavigate();

const hasUrgent = tier1Count > 0;
const [manualOpen, setManualOpen] = useState<boolean | null>(null);
const [showAll, setShowAll] = useState(false);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 bugs: If the user clicks 'Show all' and items subsequently shrink below DEFAULT_VISIBLE_COUNT (e.g., a todo is completed), showAll stays true but hasMore becomes false, hiding the button. The user can never click 'Show less' — they're stuck with showAll=true, though it's functionally harmless since slice(0, 5) on fewer items returns all of them anyway. Not a real bug, but the state is stale. [fixable]

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 bugs: When the section is collapsed (isOpen=false) and reopened, showAll retains its previous state. Similarly, if items shrink below 5 (e.g. SSE update removes items), showAll stays true but hasMore becomes false — the button correctly hides, and showAll=true with <=5 items is a no-op (slice returns all), so no actual bug. Just noting the state isn't reset.

const isOpen = manualOpen ?? true; // always open by default

const toggleOpen = useCallback(() => {
setManualOpen((prev) => !(prev ?? true));
}, []);

const toggleShowAll = useCallback(() => {
setShowAll((prev) => !prev);
}, []);

const handleTap = useCallback(
(item: AttentionItem) => {
selectionChanged();
Expand All @@ -69,6 +76,9 @@ export function AttentionFeed() {
const t2Count = items.filter((i) => i.tier === 2).length;
if (t2Count > 0) summaryParts.push(`${t2Count} in focus`);

const visibleItems = showAll ? items : items.slice(0, DEFAULT_VISIBLE_COUNT);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 missing_tests: The new show-more/show-less toggle in the component has no component-level tests. The hook test verifies the cap was removed, but there's no test for the UI slicing logic (DEFAULT_VISIBLE_COUNT), the toggle state, or that the button text changes correctly. This is consistent with the existing lack of component tests for AttentionFeed, so it's not a regression — but worth noting for a feature that introduces interactive UI state. [fixable]

const hasMore = items.length > DEFAULT_VISIBLE_COUNT;

return (
<div className="attention-section">
<button className="overview-header" onClick={toggleOpen}>
Expand All @@ -86,9 +96,14 @@ export function AttentionFeed() {
{!loading && items.length === 0 && (
<div className="attention-empty">Nothing needs your attention right now.</div>
)}
{items.map((item) => (
{visibleItems.map((item) => (
<AttentionCard key={item.id} item={item} onTap={handleTap} />
))}
{!loading && hasMore && (
<button className="attention-show-more" onClick={toggleShowAll}>
{showAll ? 'Show less' : `Show all ${items.length}`}
</button>
)}
</div>
)}
</div>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/__tests__/useAttentionFeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('useAttentionFeed', () => {
expect(result.current.items[1].tier).toBe(2);
});

it('caps output at 5 items', async () => {
it('returns all items without capping', async () => {
const items = Array.from({ length: 10 }, (_, i) =>
makeTodo({ id: `t${i}`, summary: `Item ${i}`, starred: true, urgency: 0.9 }),
);
Expand All @@ -190,7 +190,8 @@ describe('useAttentionFeed', () => {
expect(result.current.loading).toBe(false);
});

expect(result.current.items).toHaveLength(5);
expect(result.current.items).toHaveLength(10);
expect(result.current.tier1Count).toBe(10);
});

it('subscribes to SSE events for live updates', () => {
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/hooks/useAttentionFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ function sortAttention(items: AttentionItem[]): AttentionItem[] {

// ─── Hook ──────────────────────────────────────────────────────────────────

const MAX_ITEMS = 5;

export interface UseAttentionFeedReturn {
items: AttentionItem[];
tier1Count: number;
Expand Down Expand Up @@ -286,8 +284,7 @@ export function useAttentionFeed(): UseAttentionFeedReturn {
const telosItems = telosToAttention(todos);
const atbItems = atbToAttention(tasks);
const sessionItems = sessionsToAttention(activities);
const all = sortAttention([...telosItems, ...atbItems, ...sessionItems]);
return all.slice(0, MAX_ITEMS);
return sortAttention([...telosItems, ...atbItems, ...sessionItems]);
}, [todos, tasks, activities]);

const tier1Count = useMemo(() => feed.filter((i) => i.tier === 1).length, [feed]);
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,26 @@ textarea:focus {
text-align: center;
}

.attention-show-more {
width: 100%;
padding: var(--space-2) var(--space-4);
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-md);
font-size: var(--text-xs);
color: var(--primary);
font-family: inherit;
font-weight: 600;
cursor: pointer;
text-align: center;
-webkit-tap-highlight-color: transparent;
transition: background 0.15s;
}

.attention-show-more:active {
background: var(--hover);
}

.service-status {
display: flex;
gap: var(--space-4);
Expand Down
Loading