Skip to content

refactor(web): collapse like/save mutation hooks into deep optimistic-mutation module #714

Description

@thxforall

What to build

usePostLike and useSavedPost are 103-line, byte-identical hooks differing only in field names (user_has_liked/like_count vs user_has_saved/save_count), the API functions they call, their invalidation keys, and toast copy. The duplicated body holds subtle, fragile behavior — snapshot rollback, opposite-intent re-dispatch on success, pending coalescing — that today must be fixed in two places.

Collapse them into ONE deep module that takes a config object and hides the optimistic-update orchestration behind a small interface, instantiated once for likes and once for saves. The two paired vitest suites collapse into one parameterized suite that exercises both instances through the shared interface — the interface becomes the test surface.

Design constraint (load-bearing): the win only holds if the module is genuinely deep. A flat (fieldName, queryPath, mutations) signature would re-expose every varying part (two coupled fields — the boolean and the counter — a second invalidation key, and four toast strings), making the interface as wide as the body it hides → shallow again. Hide the orchestration behind a config object, not a parameter list.

Acceptance criteria

  • One optimistic-mutation module exists; usePostLike / useSavedPost are thin instantiations of it
  • Snapshot / rollback / intent-reconciliation / pending-coalesce logic lives in exactly one place
  • The two duplicate hook test suites are replaced by one parameterized suite covering both instances through the shared interface
  • No behavior change at the call sites (ImageDetailModal, ImageDetailContent); all tests pass

Blocked by

Metadata

Metadata

Assignees

Labels

ready-for-agentFully specified, ready for an AFK agenttech-debt기술 부채

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions