✨Add global snackbar#289
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe pull request replaces local snackbar handling with a queued global snackbar provider, updates scan and purchase feedback consumers, and changes analysis failures to log and re-throw instead of writing through the previous error context. ChangesGlobal Snackbar Flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Scan as Scan screen
participant BoughtButton
participant SnackbarContext
participant RootLayoutNav
participant Snackbar as Paper Snackbar
Scan->>SnackbarContext: setError(message)
BoughtButton->>SnackbarContext: showSuccess or showError(message)
SnackbarContext->>RootLayoutNav: currentSnackbar
RootLayoutNav->>Snackbar: render active message
Snackbar->>SnackbarContext: dismissSnackbar()
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ecoscan_app/app/_layout.tsx`:
- Around line 59-71: Keep the Snackbar component mounted independently of
`currentSnackbar`; use its `visible` prop to control showing and hiding, and
pass `currentSnackbar?.duration` instead of the hardcoded duration. Update
`dismissSnackbar`/the Snackbar callback flow to clear state only after the hide
transition, and remove the separate `setTimeout` from `SnackbarContext.tsx` so
Snackbar duration is the single dismissal source.
In `@ecoscan_app/hooks/useAnalyzeProduct.ts`:
- Around line 90-94: Remove the user-facing setError calls from
handleStreamError and the productData-falsy branch in analyzeProduct, allowing
the caller to display each error only once. Then remove the now-unused useError
import and setError references, including setError from analyzeProduct’s
dependency array.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b2f10290-556e-4f63-9cda-56f7fb3ccb3b
📒 Files selected for processing (6)
ecoscan_app/app/(tabs)/(scan)/index.tsxecoscan_app/app/_layout.tsxecoscan_app/components/product/BoughtButton.tsxecoscan_app/context/ErrorContext.tsxecoscan_app/context/SnackbarContext.tsxecoscan_app/hooks/useAnalyzeProduct.ts
aa8e1a2 to
79bcf3f
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ecoscan_app/hooks/useAnalyzeProduct.ts (2)
84-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePreserve the error object when logging.
console.warn("[useAnalyzeProduct] " + err)stringifieserr, discarding the stack trace and any non-message properties. Passingerras a separate argument keeps it inspectable, matching the style used inhandleStreamError(Line 34). The re-throw and updated dependency array are correct.♻️ Proposed fix
} catch (err) { setLoading(false); - console.warn("[useAnalyzeProduct] " + err); + console.warn("[useAnalyzeProduct] analyzeProduct failed:", err); throw err; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ecoscan_app/hooks/useAnalyzeProduct.ts` around lines 84 - 91, Update the catch block in useAnalyzeProduct to pass err as a separate argument to console.warn, preserving the original error object and its stack trace; keep the existing rethrow and dependency array unchanged.
27-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd
closeStreamto the hook dependency arrays.
handleStreamErrorusescloseStream(), andhandleStreamSuccessdoes too, so both callbacks should listcloseStreamin theiruseCallbackdeps to satisfyreact-hooks/exhaustive-deps.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ecoscan_app/hooks/useAnalyzeProduct.ts` around lines 27 - 37, Update the useCallback dependency arrays for handleStreamError and handleStreamSuccess to include closeStream, since both callbacks invoke it and must satisfy react-hooks/exhaustive-deps.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ecoscan_app/hooks/useAnalyzeProduct.ts`:
- Around line 84-91: Update the catch block in useAnalyzeProduct to pass err as
a separate argument to console.warn, preserving the original error object and
its stack trace; keep the existing rethrow and dependency array unchanged.
- Around line 27-37: Update the useCallback dependency arrays for
handleStreamError and handleStreamSuccess to include closeStream, since both
callbacks invoke it and must satisfy react-hooks/exhaustive-deps.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 43ed803a-cb67-4bd0-87e6-a455adaa1de2
📒 Files selected for processing (3)
ecoscan_app/app/_layout.tsxecoscan_app/context/SnackbarContext.tsxecoscan_app/hooks/useAnalyzeProduct.ts
💤 Files with no reviewable changes (1)
- ecoscan_app/context/SnackbarContext.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- ecoscan_app/app/_layout.tsx
4bb32f3 to
0cc05e0
Compare
This pull request introduces a centralized, reusable Snackbar notification system across the app, replacing previous ad-hoc error and success message handling. It removes the legacy
ErrorContextand integrates a newSnackbarContext, ensuring consistent display and management of user notifications like errors and success messages. The changes affect how errors and notifications are triggered and rendered in several key components.The most important changes are:
Snackbar System Implementation and Integration:
SnackbarContext(SnackbarProvider,useSnackbar,getSnackbarStyles) inSnackbarContext.tsxto provide global, queue-based snackbar notifications with support for multiple message types (error, success, info, warning). ([ecoscan_app/context/SnackbarContext.tsxR1-R155](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-43ccbb38a2570c3c61c0111d7639f606daa42bb1607e80f0e83f1ada9372d94eR1-R155))_layout.tsxto wrap the app inSnackbarProviderand render a single, globalSnackbarcomponent that displays messages from the new context. ([[1]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-2637e6b39c3652b6ad1edacde126efaa428cb3880883763bde4da0802e0769c2L7-R15),[[2]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-2637e6b39c3652b6ad1edacde126efaa428cb3880883763bde4da0802e0769c2L47-R85))Refactoring Error Handling:
ErrorContextand its provider, replacing it with a simplifieduseErrorhook that delegates to the new snackbar system for error display. ([ecoscan_app/context/ErrorContext.tsxR7-R21](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-9d58594457be7e9ee39982988230191f63d302f5b260e0b1a84fa51530014699R7-R21))Scanscreen andBoughtButtoncomponent to use the new snackbar-based error and success reporting, removing local state and legacy snackbar usage. ([[1]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-b3ff9cc205125bc3b78ded0e83377b57409d8f2f908628c354ad833e79cd078eL21-R32),[[2]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-b3ff9cc205125bc3b78ded0e83377b57409d8f2f908628c354ad833e79cd078eL139-L147),[[3]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-d3cb77329ca2423366324072e5410ff814a74d7c4ff8c8b0df10c44caf0305c7L15-R23),[[4]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-d3cb77329ca2423366324072e5410ff814a74d7c4ff8c8b0df10c44caf0305c7L46-L58))Code Cleanup:
[[1]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-b3ff9cc205125bc3b78ded0e83377b57409d8f2f908628c354ad833e79cd078eL1-R1),[[2]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-b3ff9cc205125bc3b78ded0e83377b57409d8f2f908628c354ad833e79cd078eL10-R10),[[3]](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-d3cb77329ca2423366324072e5410ff814a74d7c4ff8c8b0df10c44caf0305c7L1-R6))Error Logging:
useAnalyzeProductto log errors to the console instead of setting error state, as user-facing errors are now handled via the snackbar system. ([ecoscan_app/hooks/useAnalyzeProduct.tsL92-R92](https://github.com/RubberDuckCrew/EcoScan/pull/289/files#diff-7b4ab5e8caa731d0427966e9bc664f151d993c6ebaf5975fef7e7ca790fa9afbL92-R92))