Skip to content

Sync trigger + MMKV state #17

@Joel-Joseph-George

Description

@Joel-Joseph-George

Context

Background

Manual sync trigger on the home screen. Runs the fetch sequence in order
and tracks sync state in MMKV after a successful full sync.

Tasks

Sync trigger UI

  • Add a "Sync" button refer Inline sync status UI #18
  • On trigger, run the fetch sequence in this order:
    1. GET /users/:userId/projects
    2. GET /users/:userId/chapter-assignments
    3. Derive project_units from assignments
    4. POST /bibles/:bibleId/bulk-texts for each bibleId

MMKV state tracking

  • After a successful full sync, store last_synced_at timestamp in MMKV
  • After each table upsert, update the per-table count in MMKV:
    1. Read old count: storage.getNumber('sync_count_projects') ?? 0
    2. Query new count: SELECT COUNT(*) as count FROM projects
    3. Save new count: storage.set('sync_count_projects', newCount)

MMKV keys set here

Key Value Set when
last_synced_at 2024-01-04T10:32:00Z After full sync
sync_count_projects 5 After sync
sync_count_chapters 12 After sync
sync_count_bibles 3 After sync

Acceptance criteria

  • Tapping sync or pulling to refresh triggers the full fetch sequence
  • Fetch sequence runs in order — later steps depend on earlier ones
  • last_synced_at is updated in MMKV after a successful full sync
  • Per-table counts are updated in MMKV after each upsert

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In PR Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions