Skip to content

Comments

threadid in url when user opens email#492

Merged
nizzyabi merged 7 commits intostagingfrom
thread-id
Mar 20, 2025
Merged

threadid in url when user opens email#492
nizzyabi merged 7 commits intostagingfrom
thread-id

Conversation

@nizzyabi
Copy link
Collaborator

@nizzyabi nizzyabi commented Mar 20, 2025

READ CAREFULLY THEN REMOVE

Remove bullet points that are not relevant.

PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI.

  • Pull requests that do not follow these guidelines will be closed without review or comment.
  • If you use AI to write your PR description your pr will be close without review or comment.
  • If you are unsure about anything, feel free to ask for clarification.

Description

Please provide a clear description of your changes.


Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature with breaking changes)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔒 Security enhancement
  • ⚡ Performance improvement

Areas Affected

Please check all that apply:

  • Email Integration (Gmail, IMAP, etc.)
  • User Interface/Experience
  • Authentication/Authorization
  • Data Storage/Management
  • API Endpoints
  • Documentation
  • Testing Infrastructure
  • Development Workflow
  • Deployment/Infrastructure

Testing Done

Describe the tests you've done:

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

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

Add any other context about the pull request here.

Screenshots/Recordings

Add screenshots or recordings here if applicable.


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

Summary by CodeRabbit

  • New Features

    • Enhanced email thread selection: The browser’s address now reflects your current email thread, improving navigation and state awareness during use.
  • Bug Fixes

    • Streamlined handling of mail thread selection by integrating it more closely with the URL's state.
  • Style

    • Reordered class names in the ThreadSubject component for improved consistency.
  • Chores

    • Updated parameter handling and logic in the useThread function to optimize data fetching.

@vercel
Copy link

vercel bot commented Mar 20, 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 Mar 20, 2025 6:17pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request modifies the mail components by updating how email threads are managed in the MailList component. The changes use useRouter and useSearchParams from Next.js to reflect the selected thread in the browser URL. The thread selection logic within handleMailClick has been adjusted to add or remove a threadId parameter based on the user’s selection. Additionally, the ThreadSubject component’s CSS class order was reorganized without impacting functionality. The ThreadDisplay component now retrieves the threadId from the URL when the mail prop is not provided.

Changes

File(s) Change Summary
apps/mail/.../mail-list.tsx Updated thread selection logic; uses useRouter and useSearchParams to update URL with threadId; enhanced dependency management in handleMailClick.
apps/mail/.../thread-subject.tsx Reordered CSS classes in the <span> element; no functionality or behavior changes.
apps/mail/.../mail.tsx Removed mail.selected property; updated logic to use threadIdParam for thread display and state management.
apps/mail/.../thread-display.tsx Made mail prop optional; updated logic to retrieve threadId from URL if mail is not provided.
apps/mail/hooks/use-threads.ts Updated useThread function to accept id as `string

Possibly related PRs

  • fix: re-rendering #478: The changes in the main PR focus on enhancing the MailList component's URL manipulation for email thread selection, while the retrieved PR modifies the selection logic within the same MailList component by introducing a new hook for key state management.
  • fix: reduced useSession() calls ; layout inconsistencies  #432: The changes in the main PR focus on enhancing the MailList component's URL manipulation and thread selection logic, while the retrieved PR modifies the MailList component's structure and session data handling, indicating a direct relationship in their code modifications.
  • fixing the virtual mail-list #475: The changes in the main PR, which involve enhancing the MailList component's functionality with URL manipulation for email thread selection, are related to the modifications in the retrieved PR that also involve significant refactoring of the MailList component, specifically in its rendering logic and memoization.

Suggested reviewers

  • ahmetskilinc
  • MrgSub

Poem

In the code garden, I hop with delight,
Threads in the URL now shine so bright.
With hooks and routes, the mail now sings,
A reordering dance, like wind in spring.
CodeRabbit cheers with joyful hops all night!


📜 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 8803d2a and 25a2947.

📒 Files selected for processing (1)
  • apps/mail/components/mail/mail.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/mail/components/mail/mail.tsx

🪧 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 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-list.tsx (1)

389-412: Refactor handleMailClick to reduce code duplication

While the URL-based thread selection logic works well, there's some code duplication between the if and else branches. Consider refactoring to extract common code.

const handleMailClick = useCallback(
  (message: InitialThread) => () => {
    const selectMode = getSelectMode();

    // Handle other selection modes...
    
    const threadId = message.threadId ?? message.id;
    const currentParams = new URLSearchParams(searchParams.toString());
+   // Reset bulk selection regardless of selection action
+   setMail((prev) => ({
+     ...prev,
+     bulkSelected: [],
+   }));

    if (threadIdParam === threadId) {
      // Deselect the thread and update URL to remove threadId
      currentParams.delete('threadId');
-     setMail((prev) => ({
-       ...prev,
-       bulkSelected: [],
-     }));
    } else {
      // Select the thread and update URL with threadId
      currentParams.set('threadId', threadId);
-     setMail((prev) => ({
-       ...prev,
-       bulkSelected: [],
-     }));
    }

    // Update URL with new parameters
    router.push(`/mail/${folder}?${currentParams.toString()}`);

    if (message.unread) {
      return markAsRead({ ids: [message.id] })
        .then(() => mutate())
        .catch(console.error);
    }
  },
  [mail, setMail, items, getSelectMode, router, searchParams, folder],
);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a33243a and 631d0ac.

📒 Files selected for processing (4)
  • apps/mail/components/mail/mail-list.tsx (6 hunks)
  • apps/mail/components/mail/mail.tsx (6 hunks)
  • apps/mail/components/mail/thread-display.tsx (4 hunks)
  • apps/mail/hooks/use-threads.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
apps/mail/components/mail/thread-display.tsx (1)
apps/mail/hooks/use-threads.ts (1) (1)
  • useThread (114-125)
apps/mail/hooks/use-threads.ts (1)
apps/mail/types/index.ts (1) (1)
  • ParsedMessage (32-55)
🔇 Additional comments (18)
apps/mail/hooks/use-threads.ts (1)

114-118: Improved flexibility with nullable thread ID parameter

The change to accept string | null for the id parameter improves the hook's flexibility, allowing components to use it without necessarily having a thread ID. The conditional check ensures SWR only fetches data when both a valid session and thread ID exist, preventing unnecessary API calls.

apps/mail/components/mail/thread-display.tsx (4)

6-6: Added useSearchParams for URL-based thread selection

Adding this import enables retrieving the thread ID from the URL query parameters, which is essential for the overall functionality of this PR.


26-26: Making the mail prop optional accommodates URL-based selection

Making the mail prop optional allows the component to work whether the thread ID is provided via props or retrieved from the URL, which increases component flexibility.


189-193: Well-implemented thread ID retrieval logic

This code intelligently retrieves the thread ID from multiple possible sources in a clear priority order: first from props, then from URL parameters, with a sensible default. The comment also clearly explains that thread data is only fetched when a valid ID exists.


207-209: Simplified handleClose function

The handleClose function has been simplified to only call the provided onClose callback. This aligns with the new approach where thread selection state is managed through the URL rather than component state.

apps/mail/components/mail/mail.tsx (8)

200-202: Added URL parameter handling for thread selection

Using the useSearchParams hook to extract the threadId from the URL aligns with the PR objective of including thread IDs in URLs when emails are opened.


203-209: Updated thread visibility logic based on URL parameter

The component now determines whether to display a thread based on the presence of the threadId URL parameter rather than component state, creating a more consistent and sharable user experience.


211-217: Improved handleClose with URL parameter management

The function now properly updates the URL to remove the threadId parameter when closing a thread, which ensures the URL state stays in sync with the UI state.


241-242: Consistent UI visibility based on URL parameters

Using the threadIdParam to conditionally show/hide UI elements ensures consistency between the URL state and the visual state of the application.


298-298: Dynamically adjust UI based on thread selection status

The iconsOnly prop now uses the threadIdParam to determine if icons should be compact, providing a responsive UI that adapts to the current state.


343-343: Thread visibility controlled by URL parameter

The conditional rendering of the thread display now depends on the URL parameter rather than component state, completing the integration of URL-based thread selection.


351-351: Simplified ThreadDisplay component usage

The component no longer needs to receive the selected mail through props since it can retrieve the required information from the URL.


367-367: Consistent ThreadDisplay usage in mobile view

The mobile view implementation also adopts the new approach, ensuring consistency across different viewport sizes.

apps/mail/components/mail/mail-list.tsx (5)

8-8: Added router and search params for URL manipulation

Adding these imports enables the component to read from and update the URL based on user interactions with mail threads.


51-52: Retrieve thread ID from URL parameters

These lines retrieve the current thread ID from the URL, allowing the component to determine which thread is currently selected.


57-60: Updated thread selection logic to use URL parameters

The isMailSelected logic now compares against the threadId from URL parameters rather than component state, ensuring consistency between the URL and UI.


142-143: Adaptive UI based on thread selection

This conditional styling ensures the sender name is properly truncated when a thread is selected, improving the UI when viewing threads.


420-420: Updated dependencies for handleMailClick

The dependency array has been properly updated to include the new dependencies (router, searchParams, folder) required for URL manipulation.

@nizzyabi nizzyabi merged commit bc5d80e into staging Mar 20, 2025
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 10, 2025
This was referenced Apr 17, 2025
@BlankParticle BlankParticle deleted the thread-id branch May 25, 2025 13:42
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.

1 participant