Skip to content

Extract backup import logic into reusable hook - #3

Merged
kongyo2 merged 1 commit into
mainfrom
claude/similarity-ts-refactor-xbxonu
Jul 22, 2026
Merged

Extract backup import logic into reusable hook#3
kongyo2 merged 1 commit into
mainfrom
claude/similarity-ts-refactor-xbxonu

Conversation

@kongyo2

@kongyo2 kongyo2 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Refactored the backup import functionality into a reusable custom hook (useImportBackup) to eliminate code duplication across the notebook editor and cover screens. Also introduced a shared Placement type to reduce duplication in model types.

Key Changes

  • New hook: Created src/state/backup.ts with useImportBackup() hook that encapsulates the entire backup import flow (file selection, validation, confirmation dialog, and state update)
  • Removed duplication: Eliminated nearly identical onImport implementations from both src/app/notebook/[id].tsx and src/app/index.tsx
  • Type refactoring: Introduced Placement interface in src/lib/types.ts as a base type for Sticker, Shape, and Photo to consolidate common positioning properties (id, x, y, rot)
  • Updated normalization: Refactored normalizeSticker(), normalizeShape(), and normalizePhoto() in src/lib/model.ts to use the new normalizePlacement() helper function

Implementation Details

  • The useImportBackup() hook accepts an optional onImported callback that fires after successful import, allowing the notebook editor to navigate back to the cover screen
  • The hook returns an async function that can be directly assigned to UI handlers
  • Type inheritance (extends Placement) eliminates ~12 lines of duplicated property definitions across three types

https://claude.ai/code/session_01TmeSNpFwu9PqSPbejMYqBX

Driven by @kongyo2/similarity-ts (npx @kongyo2/similarity-ts . --format json),
which flagged genuine duplication. Behavior is unchanged: all 59 unit tests,
typecheck, lint and prettier pass exactly as before.

- Extract the backup-import handler duplicated across the cover screen and the
  notebook editor into a shared useImportBackup hook (src/state/backup.ts). The
  editor passes an onImported callback to navigate home, preserving each
  screen's exact behavior.
- Extract the shared id/x/y/rot fields of Sticker/Shape/Photo into a Placement
  interface, and a matching normalizePlacement helper in model.ts. newId() call
  order and count are preserved, so id assignment is identical.

Remaining similarity-ts hits (str/bool type guards, coincidental component
structure, Shape/Photo) are intentionally left as-is: collapsing them would
reduce readability without any real shared logic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmeSNpFwu9PqSPbejMYqBX
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kongyo2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Pro Plus

Run ID: 38d31e50-4043-4f6b-9f0d-72150ba9eaf8

📥 Commits

Reviewing files that changed from the base of the PR and between fefc1a8 and 5ef6f19.

📒 Files selected for processing (5)
  • src/app/index.tsx
  • src/app/notebook/[id].tsx
  • src/lib/model.ts
  • src/lib/types.ts
  • src/state/backup.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kongyo2
kongyo2 merged commit 3fa7103 into main Jul 22, 2026
5 checks passed
@kongyo2
kongyo2 deleted the claude/similarity-ts-refactor-xbxonu branch July 22, 2026 10:23
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