Skip to content

Implement .comapeocat category set import flow (connect IndexedDB → UI) #151

Description

@luandro

Problem

The Import Category Set dialog was built (file upload, Valibot validation, duplicate detection, IndexedDB persistence) and the UI was wired into CategoriesEditorScreen in PR #147. However, the import flow is a dead end:

  • importCategorySet() writes to a local IndexedDB (comapeo-categories Dexie DB)
  • CategoriesEditorScreen reads categories from the server API via useApiPresets() (TanStack Query → GET /projects/:id/presets)
  • These two data sources are not connected — nothing reads from IndexedDB
  • After import shows "success", the category list doesn't change
  • No queryClient.invalidateQueries() is called

The Import button and dialog have been commented out in CategoriesEditorScreen and its tests until the full flow is implemented.

What exists (keep + build on)

  • src/screens/CategoriesEditor/ImportSetDialog.tsx — full dialog UI (317 lines)
  • src/lib/categories-db.ts — IndexedDB layer (78 lines): importCategorySet(), getCategorySets(), getCategorySet()
  • src/lib/schemas/preset.tscomapeoCatSchema Valibot schema
  • i18n keys in all 3 locales (en/pt/es): categories.importSet.*, categories.importButton

What needs to happen

Decide on architecture before implementing:

Option A: Client-side bridge (offline-capable)

  • Create a useCategorySets() hook that reads from IndexedDB
  • Merge IndexedDB sets with server presets in CategoriesEditorScreen
  • Invalidate/refetch the hook after import
  • More complex, handles offline scenarios

Option B: Server-side import (single source of truth)

  • Upload .comapeocat file to the comapeo-cloud API
  • Server imports + stores the category set
  • queryClient.invalidateQueries(['presets']) after successful upload
  • Simpler architecture, but depends on server API support

Acceptance Criteria

  • User can upload a .comapeocat file via the Import Category Set dialog
  • After successful import, the imported categories appear in the category grid
  • Imported categories persist across page reloads
  • Replace-existing confirmation works end-to-end
  • Re-enable the commented-out UI in CategoriesEditorScreen + tests
  • Add integration test verifying the full import → render flow

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions