Refactor: extract usePredictions hook, clean up boilerplate, add validation & tests#4
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
- 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>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses all 9 cleanup/refactor items:
Deleted
src/App.css— entire file was Vite scaffold boilerplate (.hero,.counter,#center,#next-steps). Removed file + import. Also deleted unusedsrc/assets/(hero.png, react.svg, vite.svg).Cleaned
src/index.css— removed#social .button-icondark-mode rule, changed#rootfromwidth: 1126pxtomax-width: 600pxfor mobile-first.Extracted
usePredictionshook (src/hooks/usePredictions.js) — encapsulatespredictions/loading/errorstate, all CRUD functions, initialloadAll()with error handling, and a derivedresolvedItemsarray.App.jsxis now a pure layout component.ScoreSummaryandReliabilityDiagramacceptresolvedItemsdirectly instead of computing it themselves.Created
src/constants.js—CATEGORIESmoved out ofPredictionForm.Added import validation in
DataIO— afterArray.isArraycheck, validates each item hasid(string),text(string),probability(number 0–1) with descriptive per-item errors.Batched DB writes —
importPredictionsnow usesPromise.all(incoming.map(put))instead of sequentialawait put().Error handling for DB load —
.catch()onloadAll()setserrorstate; UI shows arole="alert"message instead of stuck "Loading…".PWA icons verified —
pwa-192.pngandpwa-512.pngalready exist inpublic/. No changes needed.Added tests (22 total, all passing):
test/dataio-validation.test.jsx— validation rejects bad data, accepts validtest/prediction-list.test.jsx— due-first sorting, open/resolved separationtest/use-predictions.test.js— load, error, add, resolve, delete, import,resolvedItemsderivationLink to Devin session: https://app.devin.ai/sessions/0c9ec8f0262840b59ae394ddce98ddb7
Requested by: @tcballard