Skip to content

✨Add global snackbar#289

Merged
IamPekka058 merged 8 commits into
mainfrom
chore/global-snackbar
Jul 10, 2026
Merged

✨Add global snackbar#289
IamPekka058 merged 8 commits into
mainfrom
chore/global-snackbar

Conversation

@IamPekka058

Copy link
Copy Markdown
Member

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 ErrorContext and integrates a new SnackbarContext, 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:

  • Added a new SnackbarContext (SnackbarProvider, useSnackbar, getSnackbarStyles) in SnackbarContext.tsx to 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))
  • Updated the app layout in _layout.tsx to wrap the app in SnackbarProvider and render a single, global Snackbar component 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:

  • Removed the old ErrorContext and its provider, replacing it with a simplified useError hook 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))
  • Updated the Scan screen and BoughtButton component 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:

  • Removed unused imports and state variables related to the old snackbar and error handling mechanisms in affected files. ([[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:

  • Changed error handling in useAnalyzeProduct to 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))

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c64c9bb3-c616-4238-884f-a815437d7cc1

📥 Commits

Reviewing files that changed from the base of the PR and between 79bcf3f and 0cc05e0.

📒 Files selected for processing (1)
  • ecoscan_app/hooks/useAnalyzeProduct.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • ecoscan_app/hooks/useAnalyzeProduct.ts

Walkthrough

The 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.

Changes

Global Snackbar Flow

Layer / File(s) Summary
Snackbar context and error adapter
ecoscan_app/context/SnackbarContext.tsx, ecoscan_app/context/ErrorContext.tsx
Adds typed snackbar messages, FIFO queueing, durations, styles, dismissal, and a useError adapter backed by useSnackbar.
Root snackbar rendering
ecoscan_app/app/_layout.tsx
Provides snackbar state at the app root and renders the active message with styling, duration, and dismissal handling.
Scan, purchase, and analysis feedback
ecoscan_app/app/(tabs)/(scan)/index.tsx, ecoscan_app/components/product/BoughtButton.tsx, ecoscan_app/hooks/useAnalyzeProduct.ts
Routes scan and purchase outcomes through shared snackbar actions, removes screen-local snackbar UI, and logs/re-throws analysis errors.

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()
Loading

Possibly related PRs

Suggested labels: ✨ Enhancement, ♻️ Refactor, 💄 UI/UX

Suggested reviewers: Friedinger

Poem

I’m a rabbit with snacks in a queue,
Green success and red errors come through.
Scan, save, or warn—
The root keeps them warm,
With a dismiss button hopping on cue. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: introducing a global snackbar system.
Description check ✅ Passed The description is directly about the snackbar refactor and related error handling changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/global-snackbar

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.

@github-actions github-actions Bot added the 🛠️ Maintenance General maintenance and updates label Jul 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1c265 and 28f72e7.

📒 Files selected for processing (6)
  • ecoscan_app/app/(tabs)/(scan)/index.tsx
  • ecoscan_app/app/_layout.tsx
  • ecoscan_app/components/product/BoughtButton.tsx
  • ecoscan_app/context/ErrorContext.tsx
  • ecoscan_app/context/SnackbarContext.tsx
  • ecoscan_app/hooks/useAnalyzeProduct.ts

Comment thread ecoscan_app/app/_layout.tsx Outdated
Comment thread ecoscan_app/hooks/useAnalyzeProduct.ts
@IamPekka058 IamPekka058 force-pushed the chore/global-snackbar branch from aa8e1a2 to 79bcf3f Compare July 10, 2026 11:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
ecoscan_app/hooks/useAnalyzeProduct.ts (2)

84-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Preserve the error object when logging.

console.warn("[useAnalyzeProduct] " + err) stringifies err, discarding the stack trace and any non-message properties. Passing err as a separate argument keeps it inspectable, matching the style used in handleStreamError (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 value

Add closeStream to the hook dependency arrays.

handleStreamError uses closeStream(), and handleStreamSuccess does too, so both callbacks should list closeStream in their useCallback deps to satisfy react-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

📥 Commits

Reviewing files that changed from the base of the PR and between 28f72e7 and 79bcf3f.

📒 Files selected for processing (3)
  • ecoscan_app/app/_layout.tsx
  • ecoscan_app/context/SnackbarContext.tsx
  • ecoscan_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

@IamPekka058 IamPekka058 force-pushed the chore/global-snackbar branch from 4bb32f3 to 0cc05e0 Compare July 10, 2026 12:04
@IamPekka058 IamPekka058 marked this pull request as ready for review July 10, 2026 12:07
@Friedinger Friedinger self-requested a review July 10, 2026 13:39
@IamPekka058 IamPekka058 merged commit 7fe580b into main Jul 10, 2026
10 checks passed
@IamPekka058 IamPekka058 deleted the chore/global-snackbar branch July 10, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ Maintenance General maintenance and updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants