Skip to content

Conversation

@flegaspi700
Copy link
Owner

No description provided.

- Fix 'children' prop missing error by passing undefined instead of empty
- All 11 tests still passing
- Resolves TypeScript compilation error
TDD Red Phase:
- Created 8 failing tests for sorting stability and pin functionality
- Tests covered: load without reorder, pin/unpin, mixed sorting

Root Cause Analysis:
- saveConversation() updated updatedAt timestamp even when loading
- loadConversations() sorted by updatedAt descending
- Result: Selected conversation jumped to top of list

TDD Green Phase - Sorting Fix:
- Added updateTimestamp parameter to saveConversation() (default: true)
- Added isLoadingConversationRef flag in page.tsx
- Auto-save effect skips when loading conversation from history
- Conversations only reorder when content actually changes

TDD Green Phase - Pin Feature:
- Added isPinned field to Conversation type
- Added togglePinConversation() function in storage.ts
- Updated loadConversations() to sort: pinned first, then unpinned
- Both sections sorted by updatedAt descending
- Backwards compatible: isPinned defaults to false

UI Implementation:
- Added Star icon button to conversation items
- Visual distinction: yellow background for pinned conversations
- Filled star for pinned, outline for unpinned
- Toast notifications on pin/unpin actions
- Hover states and accessibility labels

Testing Results:
- All 8 new tests passing
- All 519 existing tests passing (no regressions)
- Test file: src/__tests__/lib/conversation-sorting.test.ts

Documentation:
- Updated README.md with new feature
- Documented issue resolution in docs/04-development/issues/
- Added to recent updates section

Impact:
- Conversation list stays stable when browsing history
- Important conversations can be pinned to top
- Better UX for power users with many conversations
TypeScript was complaining that 'ai' string literal wasn't assignable
to the union type 'user' | 'ai'. Using 'as const' ensures the literal
type is preserved.

Fixes CI typecheck error.
@flegaspi700 flegaspi700 merged commit eeeeefa into main Nov 4, 2025
2 checks passed
@flegaspi700 flegaspi700 deleted the feat/conversation-sorting-and-pinning branch November 4, 2025 17:02
flegaspi700 added a commit that referenced this pull request Nov 4, 2025
Found three locations where saveConversation() was updating timestamps
during conversation loads, causing list to reorder:

1. ✅ saveConversation() itself - added updateTimestamp parameter (PR #23)
2. ✅ handleLoadConversation() - now uses updateTimestamp: false
3. ✅ Auto-save effect - now uses updateTimestamp: false

The auto-save effect was triggering when currentConversationId changed
during load. Even with isLoadingConversationRef flag, the effect would
run and update the timestamp.

Solution:
- Auto-save effect now uses updateTimestamp: false to prevent timestamp
  updates when just preserving state
- Explicit timestamp update added in onComplete callback when user sends
  new messages (the only time we actually want to update the timestamp)

This ensures conversations only move to top when users send new messages,
not when just selecting from history.

Fixes persistent sorting issue confirmed by user.
flegaspi700 added a commit that referenced this pull request Nov 4, 2025
* fix: prevent timestamp updates during conversation loads (complete fix)

Found three locations where saveConversation() was updating timestamps
during conversation loads, causing list to reorder:

1. ✅ saveConversation() itself - added updateTimestamp parameter (PR #23)
2. ✅ handleLoadConversation() - now uses updateTimestamp: false
3. ✅ Auto-save effect - now uses updateTimestamp: false

The auto-save effect was triggering when currentConversationId changed
during load. Even with isLoadingConversationRef flag, the effect would
run and update the timestamp.

Solution:
- Auto-save effect now uses updateTimestamp: false to prevent timestamp
  updates when just preserving state
- Explicit timestamp update added in onComplete callback when user sends
  new messages (the only time we actually want to update the timestamp)

This ensures conversations only move to top when users send new messages,
not when just selecting from history.

Fixes persistent sorting issue confirmed by user.

* fix: remove currentConversationId from auto-save effect dependencies

The root cause was the auto-save effect depending on currentConversationId.
When loading a conversation, setCurrentConversationId() would trigger the
effect, causing an unwanted save that updated the timestamp.

Changes:
1. Removed currentConversationId from effect dependencies
2. Removed "|| currentConversationId" from the if condition (only save when there are messages)
3. Added explicit saveConversation(conversation, true) in onComplete callback to update timestamp when user sends messages
4. Updated comments to explain why currentConversationId is not in dependencies

This ensures the effect only runs when actual content (messages, files, aiTheme) changes,
not when just switching conversations.

Fixes the persistent sorting issue where conversations jump to top when selected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants