Skip to content

Refactor: extract usePredictions hook, clean up boilerplate, add validation & tests#4

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780425291-cleanup-and-refactor
Open

Refactor: extract usePredictions hook, clean up boilerplate, add validation & tests#4
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1780425291-cleanup-and-refactor

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 2, 2026

Copy link
Copy Markdown

Summary

Addresses all 9 cleanup/refactor items:

  1. Deleted src/App.css — entire file was Vite scaffold boilerplate (.hero, .counter, #center, #next-steps). Removed file + import. Also deleted unused src/assets/ (hero.png, react.svg, vite.svg).

  2. Cleaned src/index.css — removed #social .button-icon dark-mode rule, changed #root from width: 1126px to max-width: 600px for mobile-first.

  3. Extracted usePredictions hook (src/hooks/usePredictions.js) — encapsulates predictions/loading/error state, all CRUD functions, initial loadAll() with error handling, and a derived resolvedItems array. App.jsx is now a pure layout component. ScoreSummary and ReliabilityDiagram accept resolvedItems directly instead of computing it themselves.

  4. Created src/constants.jsCATEGORIES moved out of PredictionForm.

  5. Added import validation in DataIO — after Array.isArray check, validates each item has id (string), text (string), probability (number 0–1) with descriptive per-item errors.

  6. Batched DB writesimportPredictions now uses Promise.all(incoming.map(put)) instead of sequential await put().

  7. Error handling for DB load.catch() on loadAll() sets error state; UI shows a role="alert" message instead of stuck "Loading…".

  8. PWA icons verifiedpwa-192.png and pwa-512.png already exist in public/. No changes needed.

  9. Added tests (22 total, all passing):

    • test/dataio-validation.test.jsx — validation rejects bad data, accepts valid
    • test/prediction-list.test.jsx — due-first sorting, open/resolved separation
    • test/use-predictions.test.js — load, error, add, resolve, delete, import, resolvedItems derivation

Link to Devin session: https://app.devin.ai/sessions/0c9ec8f0262840b59ae394ddce98ddb7
Requested by: @tcballard


Open in Devin Review

- Remove boilerplate App.css and unused scaffold assets
- Clean up index.css: remove #social dark-mode rule, set #root max-width to 600px
- Extract usePredictions hook with error handling and batched imports
- Move CATEGORIES to src/constants.js
- Add import validation in DataIO (id, text, probability)
- Batch DB writes in importPredictions via Promise.all
- Add error state for failed DB load
- Update ScoreSummary and ReliabilityDiagram to accept resolvedItems prop
- Add tests: DataIO validation, PredictionList sorting, usePredictions hook
- Add jsdom test environment and @testing-library/react

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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.

1 participant