feat: add pull sync on login with conflict resolution

- Created highlight-pull-sync.ts with pullAndMergeHighlights function
- Integrated pull sync into BibleReaderApp on mount
- Fetches server highlights, merges with local using conflict resolution
- Updates local storage and component state with merged data

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-12 07:51:35 +00:00
parent 73171b5f18
commit 3e3e90f774
2 changed files with 58 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import { VersDetailsPanel } from './verse-details-panel'
import { ReadingSettings } from './reading-settings'
import { HighlightSyncManager } from '@/lib/highlight-sync-manager'
import { addHighlight, updateHighlight, getHighlightsByVerse, deleteHighlight, getAllHighlights } from '@/lib/highlight-manager'
import { pullAndMergeHighlights } from '@/lib/highlight-pull-sync'
interface BookInfo {
id: string // UUID
@@ -61,6 +62,21 @@ export function BibleReaderApp() {
}
}, [])
// Pull highlights from server when component mounts (user logged in)
useEffect(() => {
const pullHighlights = async () => {
try {
const merged = await pullAndMergeHighlights()
const map = new Map(merged.map(h => [h.verseId, h]))
setHighlights(map)
} catch (error) {
console.error('Failed to pull highlights:', error)
}
}
pullHighlights()
}, [])
// Load all highlights on mount
useEffect(() => {
loadAllHighlights()