feat: add native notifications for promise toasts #1216
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.
Pull Request Title:
Add Browser Notification Support to
toast.promise
Description:
This PR introduces an optional browser notification feature for
toast.promise
. When enabled, it allows developers to trigger native browser notifications upon promise resolution or rejection. This is particularly useful for notifying users who have switched to another tab or are not actively viewing the application.Key Features:
browserNotification
option insidetoast.promise
:success
anderror
states.isUserActiveInTab
: Determines if the user is currently active in the tab.createBrowserNotification
: Handles the creation of browser notifications with proper permission handling.toast.promise
behavior.Notification
API.Usage Example:
Why This Change?
Users might not always stay on the same tab while waiting for an operation to complete. This feature improves user experience by ensuring they receive real-time updates even when they switch tabs.
Affected Files:
src/core/toast.ts
→ IntegratedbrowserNotification
logic.src/utils/userActionInfo.ts
→ AddedisUserActiveInTab
andcreateBrowserNotification
.src/utils/index.ts
→ Exported new utility functions.src/core/toast.cy.tsx
→ Added test cases for browser notifications.Checklist:
README.md
)Looking forward to your review! 🚀