Extract backup import logic into reusable hook - #3
Conversation
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
|
Warning Review limit reached
Next review available in: 22 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: QUIET Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
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. Comment |
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 sharedPlacementtype to reduce duplication in model types.Key Changes
src/state/backup.tswithuseImportBackup()hook that encapsulates the entire backup import flow (file selection, validation, confirmation dialog, and state update)onImportimplementations from bothsrc/app/notebook/[id].tsxandsrc/app/index.tsxPlacementinterface insrc/lib/types.tsas a base type forSticker,Shape, andPhototo consolidate common positioning properties (id, x, y, rot)normalizeSticker(),normalizeShape(), andnormalizePhoto()insrc/lib/model.tsto use the newnormalizePlacement()helper functionImplementation Details
useImportBackup()hook accepts an optionalonImportedcallback that fires after successful import, allowing the notebook editor to navigate back to the cover screenextends Placement) eliminates ~12 lines of duplicated property definitions across three typeshttps://claude.ai/code/session_01TmeSNpFwu9PqSPbejMYqBX