Skip to content

Feature/mark as read#599

Merged
MrgSub merged 7 commits intoMail-0:stagingfrom
Rajmeet:feature/mark-as-read
Apr 6, 2025
Merged

Feature/mark as read#599
MrgSub merged 7 commits intoMail-0:stagingfrom
Rajmeet:feature/mark-as-read

Conversation

@Rajmeet
Copy link
Contributor

@Rajmeet Rajmeet commented Apr 5, 2025

Description

  • Added MailOpen Lucide React Icon
  • Imported markAsRead Action from actions/mail
  • Created a new handler handleMarkAsRead for calling the action and if successful shows mark as read successful.
  • Added a tooltip button to trigger

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🎨 UI/UX improvement

Areas Affected

Please check all that apply:

  • User Interface/Experience

Testing Done

Describe the tests you've done:

  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

Additional Notes

Screenshots/Recordings

Add screenshots or recordings here if applicable.

Screencast.From.2025-04-05.16-26-18.mp4

By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a bulk-action capability that enables users to mark multiple emails as read with a single click. A new user interface button with a descriptive tooltip now triggers this action, providing immediate feedback and updating email statuses instantly.
  • Improvements
    • Enhanced control flow for marking emails as read, integrating it with existing bulk selection functionality.

@vercel
Copy link

vercel bot commented Apr 5, 2025

@Rajmeet is attempting to deploy a commit to the Zero Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 5, 2025

Walkthrough

The changes introduce a feature in the BulkSelectActions component to mark selected emails as read. An asynchronous function handleMarkAsRead is added, which retrieves the IDs from the current selection, calls the markAsRead function, and, upon success, updates threads and stats, clears the bulk selection state, and displays a success toast. A new UI button with a tooltip has been implemented to trigger this functionality. Additionally, minor formatting adjustments have been made.

Changes

File(s) Change Summary
apps/mail/.../mail.tsx - Added markAsRead import alongside getMail.
- Introduced handleMarkAsRead using useCallback to mark emails as read.
- Added a new button with MailOpen icon wrapped in a tooltip.
- Performed minor formatting adjustments.

Possibly related PRs

  • thread action buttons #597: Addresses a similar bulk email action by implementing a function for marking emails as unread, indicating shared updates in bulk email operations.

Suggested reviewers

  • MrgSub
  • ahmetskilinc

Poem

I'm a bunny in the mail domain, hopping quick and light,
Marking emails as read with a single button's might.
With callbacks and toasts, my work is neat and fun,
Threads and stats updated, every job well done.
Hoppy coding to all, in this email run!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48f8138 and 5ec60bd.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/components/mail/mail.tsx (1)
apps/mail/actions/mail.ts (1)
  • markAsRead (45-55)
🔇 Additional comments (4)
apps/mail/components/mail/mail.tsx (4)

18-18: Good choice of icon for the feature.

The MailOpen icon from Lucide React is semantically appropriate for the "mark as read" functionality, providing a clear visual cue for users.


58-58: Properly imported the required action.

The import statement correctly includes the markAsRead function alongside the existing getMail import, following the established pattern in the codebase.


484-500: Well-implemented handler with proper error handling and state updates.

The handleMarkAsRead function is well-structured:

  • Uses useCallback with the correct dependency array
  • Properly handles success and error cases
  • Updates both threads and stats upon success
  • Clears the bulk selection state after completion
  • Provides user feedback with toast notifications

571-582: UI implementation maintains design consistency.

The new button for marking emails as read:

  • Follows the same styling pattern as other action buttons
  • Uses the appropriate icon with tooltip
  • Is positioned logically among other bulk actions
  • Uses the translation system correctly for internationalization
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/mail/components/mail/mail.tsx (1)

484-495: Consider adding error handling to the markAsRead function

The implementation of the handleMarkAsRead function looks good, but it doesn't include any error handling. If the markAsRead action fails for any reason, the error will propagate without any user feedback.

const handleMarkAsRead = useCallback(async () => {
-  const response = await markAsRead({ ids: mail.bulkSelected });
-  if (response.success) {
-    await mutateThreads();
-    await mutateStats();
-    setMail((prev) => ({
-      ...prev,
-      bulkSelected: []
-    }));
-    toast.success(t('common.mail.markedAsRead'));
-  }
+  try {
+    const response = await markAsRead({ ids: mail.bulkSelected });
+    if (response.success) {
+      await mutateThreads();
+      await mutateStats();
+      setMail((prev) => ({
+        ...prev,
+        bulkSelected: []
+      }));
+      toast.success(t('common.mail.markedAsRead'));
+    }
+  } catch (error) {
+    console.error('Error marking as read:', error);
+    toast.error(t('common.errors.generic'));
+  }
}, [mail, setMail, mutateThreads, mutateStats, t]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc8ab8a and 245cd0b.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/components/mail/mail.tsx (1)
apps/mail/actions/mail.ts (1)
  • markAsRead (45-55)
🔇 Additional comments (3)
apps/mail/components/mail/mail.tsx (3)

18-18: LGTM: Added MailOpen icon for the mark as read functionality

The MailOpen icon from lucide-react has been appropriately imported to represent the mark as read action in the UI.


58-58: LGTM: Imported markAsRead action

Correctly imported the markAsRead action from the mail actions module to implement the new functionality.


566-577: LGTM: UI implementation for mark as read functionality

The button implementation for the mark as read functionality has been correctly added to the bulk actions toolbar. It follows the established UI pattern with proper tooltips and consistent styling.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 245cd0b and 48f8138.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/components/mail/mail.tsx (1)
apps/mail/actions/mail.ts (1)
  • markAsRead (45-55)
🔇 Additional comments (3)
apps/mail/components/mail/mail.tsx (3)

18-18: Good choice of icon for the feature.

The MailOpen icon is an intuitive choice for the "mark as read" functionality, making the UI element self-explanatory even before users see the tooltip.


58-58: Import statement addition looks good.

Correctly importing the markAsRead function alongside the existing getMail import from the actions module.


571-582: Implementation of UI button looks good.

The button is well-integrated with the existing UI patterns - it uses consistent styling with other action buttons, has appropriate tooltips for accessibility, and is properly positioned in the bulk actions toolbar.

Comment on lines 484 to 500
const handleMarkAsRead = useCallback(async () => {
try {
const response = await markAsRead({ ids: mail.bulkSelected });
if (response.success) {
await mutateThreads();
await mutateStats();
setMail((prev) => ({
...prev,
bulkSelected: []
}));
toast.success(t('common.mail.markedAsRead'));
}
} catch (error) {
console.error("Error marking as read", error);
toast.error("common.errors.generic");
}
}, [mail, setMail, mutateThreads, mutateStats, t]);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix translation key in error toast.

The handleMarkAsRead function has a well-structured implementation with proper error handling, state updates, and notifications. However, there's an issue with the error toast - it uses a hardcoded string instead of the translation function.

- toast.error("common.errors.generic");
+ toast.error(t("common.errors.generic"));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleMarkAsRead = useCallback(async () => {
try {
const response = await markAsRead({ ids: mail.bulkSelected });
if (response.success) {
await mutateThreads();
await mutateStats();
setMail((prev) => ({
...prev,
bulkSelected: []
}));
toast.success(t('common.mail.markedAsRead'));
}
} catch (error) {
console.error("Error marking as read", error);
toast.error("common.errors.generic");
}
}, [mail, setMail, mutateThreads, mutateStats, t]);
const handleMarkAsRead = useCallback(async () => {
try {
const response = await markAsRead({ ids: mail.bulkSelected });
if (response.success) {
await mutateThreads();
await mutateStats();
setMail((prev) => ({
...prev,
bulkSelected: []
}));
toast.success(t('common.mail.markedAsRead'));
}
} catch (error) {
console.error("Error marking as read", error);
toast.error(t("common.errors.generic"));
}
}, [mail, setMail, mutateThreads, mutateStats, t]);

@vercel
Copy link

vercel bot commented Apr 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
0 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 6, 2025 4:33am

@MrgSub MrgSub merged commit f090c04 into Mail-0:staging Apr 6, 2025
4 checks passed
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.

4 participants