Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Forward Update #999

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

- Forward Update #999

wants to merge 6 commits into from

Conversation

Gamius00
Copy link
Collaborator

@Gamius00 Gamius00 commented Jan 31, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new message forwarding capability that lets users forward messages to selected chats via an interactive dialog with recipient selection and confirmation.
    • Added enhanced selection controls for a more intuitive user experience when choosing recipients.
  • Chores

    • Performed updates to various dependencies to boost performance and overall application stability.

Copy link

vercel bot commented Jan 31, 2025

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

Name Status Preview Comments Updated (UTC)
chat-io ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 9, 2025 5:44pm

Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

This pull request introduces a message forwarding feature that spans both server and client components. A new mutation, forwardMessage, is added to handle message forwarding with authentication and chat membership checks. On the client side, new components and state handling (ForwardDialog and ForwardHandler) enable users to select recipients and submit forwarding actions. Additionally, a Chats type is now exported for external use, and a new Checkbox component is added for UI interactions. Package dependencies and devDependencies are updated, with several packages being removed or upgraded.

Changes

Files Summary
convex/messages.ts, src/components/forwardMessage.tsx, src/components/message.tsx Adds forward message functionality: the forwardMessage mutation processes auth checks and message validation; ForwardDialog (with interfaces and state) provides the UI; Message component integrates the new flow.
package.json Updates dependencies and devDependencies: several packages are upgraded (e.g., @clerk/nextjs, @floating-ui/react, etc.), while some packages are removed to streamline the dependency list.
src/components/chat-overview.tsx Changes the Chats type declaration from a local to an exported type, allowing it to be used in other parts of the application.
src/components/ui/checkbox.tsx Introduces a new Checkbox component built with @radix-ui/react-checkbox, featuring ref forwarding and styling via a utility function.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as Message Component
    participant D as ForwardDialog
    participant S as Convex Server

    U->>M: Initiate forward action
    M->>D: Set forwardedMessageId & display dialog
    U->>D: Select recipients & submit forwarding
    D->>S: Call forwardMessage mutation with forwardObjects & messageId
    S-->>D: Return response (success/error)
    D-->>M: Notify update to UI
Loading

Poem

I’m hopping through code with a joyful beat,
Forwarding messages is a brand new feat.
From server checks to dialog delight,
Each change shines, crisp and bright.
Dependencies trimmed, features unfurled—
A rabbit’s cheer for a better world!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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.

@Gamius00 Gamius00 linked an issue Jan 31, 2025 that may be closed by this pull request
src/components/message.tsx Outdated Show resolved Hide resolved
src/components/message.tsx Outdated Show resolved Hide resolved
src/components/forwardMessage.tsx Outdated Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
convex/messages.ts Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
@FleetAdmiralJakob
Copy link
Owner

FleetAdmiralJakob commented Feb 3, 2025

Things that need to be done before merge:

  • Show me why you can't change the type from string to Id<"messages">
  • Polish UI
  • Add Loading spinner instead of "loading" text
  • Clean up code

@Gamius00 Gamius00 marked this pull request as ready for review February 9, 2025 17:41
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: 3

♻️ Duplicate comments (2)
convex/messages.ts (2)

289-289: ⚠️ Potential issue

Change type from string to Id<"messages">.

As per PR objectives and past review comments, the type for messageId should be changed from string to Id<"messages">.

Apply this diff:

-    messageId: v.string(),
+    messageId: v.id("messages"),

295-297: 🛠️ Refactor suggestion

Remove console.log in production.

Console.log statements should not be present in production code.

Apply this diff:

-      console.error("Unauthenticated call to mutation");
-      return null;
+      throw new ConvexError("Unauthenticated call to mutation");
🧹 Nitpick comments (6)
src/components/forwardMessage.tsx (3)

73-73: Fix typo in dialog title.

There's a typo in the dialog title: "Fordward" should be "Forward".

Apply this diff:

-            <p className="mt-1">Fordward</p>{" "}
+            <p className="mt-1">Forward</p>{" "}

84-86: Enhance loading state UI.

The loading state could be improved to provide better user feedback.

Consider applying this diff for a more polished loading state:

-            <LoaderCircle className="mr-1.5 animate-spin justify-center p-0.5" />
+            <div className="flex flex-col items-center justify-center space-y-2">
+              <LoaderCircle className="h-8 w-8 animate-spin" />
+              <p className="text-sm text-muted-foreground">Loading chats...</p>
+            </div>

128-133: Simplify conditional className.

The conditional className logic can be simplified.

Apply this diff:

-                      className={cn(
-                        "mt-4 flex cursor-pointer rounded-xl bg-secondary p-5",
-                        user.username == userInfos[0]?.username
-                          ? "h-0 p-0"
-                          : null,
-                      )}
+                      className={cn("mt-4 flex cursor-pointer rounded-xl bg-secondary p-5", {
+                        "h-0 p-0": user.username == userInfos[0]?.username
+                      })}
convex/messages.ts (1)

314-324: Remove redundant message existence check.

The message existence check is redundant since getX will throw if the message doesn't exist.

Apply this diff:

-      const parsedMessageId = ctx.table("messages").normalizeId(args.messageId);
-
-      if (!parsedMessageId) {
-        throw new ConvexError("messageId was invalid");
-      }
-
-      const message = await ctx.table("messages").getX(parsedMessageId);
-
-      if (!message) {
-        throw new ConvexError("Message does not exist");
-      }
+      const message = await ctx.table("messages").getX(args.messageId);
src/components/message.tsx (2)

275-279: Follow React's naming convention for state variables.

The state variable and setter function should follow camelCase naming convention:

-const [ForwardedMessageId, setForwardedMessageId] = useQueryState(
+const [forwardedMessageId, setForwardedMessageId] = useQueryState(

281-283: Follow React's naming convention for event handlers.

The handler function should follow camelCase naming convention:

-const ForwardHandler = () => {
+const handleForward = () => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e49d172 and fe01061.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • convex/messages.ts (1 hunks)
  • package.json (1 hunks)
  • src/components/chat-overview.tsx (1 hunks)
  • src/components/forwardMessage.tsx (1 hunks)
  • src/components/message.tsx (6 hunks)
  • src/components/ui/checkbox.tsx (1 hunks)
🔇 Additional comments (3)
src/components/ui/checkbox.tsx (1)

1-29: LGTM! Well-structured Checkbox component.

The component is well-implemented with proper accessibility support through Radix UI, correct usage of forward ref pattern, and clean styling implementation.

src/components/chat-overview.tsx (1)

16-16: LGTM! Appropriate type export.

The Chats type is now correctly exported for use in other components.

package.json (1)

18-92: 🌐 Web query:

What is the latest version of Next.js?

💡 Result:

The latest stable version of Next.js as of February 2025 is **Next.js 15**, with its most recent patch being **15.1.6** released on January 22, 2025[1][3]. This version requires React 19 and introduces several improvements including core upgrades, new APIs, and enhanced developer experience[2][3].

Key details about current releases:
- **Stable channel**: v15.x (security-supported)
- **Latest patch**: v15.1.6
- **Previous supported version**: v14.2.23 (security updates until January 2025)[1]

The development team has also been working on Next.js 15.2 in canary releases (pre-release versions), with multiple test builds like v15.2.0-canary.47 published in February 2025[4]. However, these canary releases are not recommended for production use[1].

To check your current version:
```bash
npx next --version
```

To upgrade an existing project:
```bash
npm i next@latest react@latest react-dom@latest eslint-config-next@latest
```

Citations:

- 1: https://endoflife.date/nextjs
- 2: https://nextjs.org/blog
- 3: https://nextjs.org/docs/app/building-your-application/upgrading/version-15
- 4: https://github.com/vercel/next.js/releases
- 5: https://nextjs.org
- 6: https://www.npmjs.com/package/next

🌐 Web query:

What is the latest version of React?

💡 Result:

The latest version of React is **19.0**, released on December 5, 2024[1][2][4][7]. This major update introduces significant features like:

- **Actions**: Simplified form handling with automatic state management.
- **New hooks**: `useActionState`, `useFormStatus`, and `useOptimistic` for enhanced state control.
- **Server Components**: Native support for server-rendered components with async capabilities[2][7].
- **Improved hydration**: Better error reporting and reduced client-server mismatch errors[2].
- **Ref handling**: Can now pass refs as normal props instead of using `forwardRef`[2].

Key development recommendations:
- Upgrade path: First migrate to React 18.3.x to identify deprecated API usage before moving to v19[2].
- Concurrent features: Enabled by default in the new root API (`ReactDOM.createRoot`)[6].
- Support status: Active security updates and non-critical bug fixes are ongoing for v19[4].

Previous major versions like React 18 (March 2022) introduced concurrent rendering and automatic batching[3][5], while React 17 (October 2020) focused on gradual upgrade capabilities[3][4]. The npm package `react@latest` currently points to v19.0.0[10].

Citations:

- 1: https://react.dev/versions
- 2: https://github.com/facebook/react/releases
- 3: https://en.wikipedia.org/wiki/React_(JavaScript_library)
- 4: https://endoflife.date/react
- 5: https://www.scalablepath.com/react/react-18-release-features
- 6: https://www.w3schools.com/react/react_upgrade.asp
- 7: https://react.dev/blog/2024/12/05/react-19
- 8: https://www.simplilearn.com/tutorials/reactjs-tutorial/react-eighteen-new-features
- 9: https://legacy.reactjs.org/versions
- 10: https://www.npmjs.com/package/react

Comment on lines +20 to +21
interface ForwardDialogProps {
ForwardedMessageId: string;
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

Change type from string to Id<"messages">.

As per PR objectives, the type for ForwardedMessageId should be changed from string to Id<"messages">.

Apply this diff:

-  ForwardedMessageId: string;
+  ForwardedMessageId: Id<"messages">;
📝 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
interface ForwardDialogProps {
ForwardedMessageId: string;
interface ForwardDialogProps {
ForwardedMessageId: Id<"messages">;

Comment on lines +796 to +810
<div
onClick={() => {
ForwardHandler();
}}
className="flex w-full cursor-pointer border-b-2 border-secondary-foreground p-2 pr-8"
>
<Forward />
<p className="ml-1">Forward</p>
</div>
<ForwardDialog
ForwardedMessageId={ForwardedMessageId}
setForwardedMessageId={setForwardedMessageId}
chats={existingChats}
userInfos={userInfos}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use a button element for better accessibility.

Replace the div with a button element to improve accessibility:

-<div
+<button
  onClick={() => {
-    ForwardHandler();
+    handleForward();
  }}
  className="flex w-full cursor-pointer border-b-2 border-secondary-foreground p-2 pr-8"
->
+>
  <Forward />
  <p className="ml-1">Forward</p>
-</div>
+</button>

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +606 to +620
<div
className="flex w-full cursor-pointer border-t-2 border-secondary-foreground p-2 pr-8"
onClick={() => {
ForwardHandler();
}}
>
<Forward />
<p className="ml-1">Forward</p>
</div>
<ForwardDialog
ForwardedMessageId={ForwardedMessageId}
setForwardedMessageId={setForwardedMessageId}
chats={existingChats}
userInfos={userInfos}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use a button element for better accessibility.

Replace the div with a button element to improve accessibility:

-<div
+<button
  className="flex w-full cursor-pointer border-t-2 border-secondary-foreground p-2 pr-8"
  onClick={() => {
-    ForwardHandler();
+    handleForward();
  }}
->
+>
  <Forward />
  <p className="ml-1">Forward</p>
-</div>
+</button>
📝 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
<div
className="flex w-full cursor-pointer border-t-2 border-secondary-foreground p-2 pr-8"
onClick={() => {
ForwardHandler();
}}
>
<Forward />
<p className="ml-1">Forward</p>
</div>
<ForwardDialog
ForwardedMessageId={ForwardedMessageId}
setForwardedMessageId={setForwardedMessageId}
chats={existingChats}
userInfos={userInfos}
/>
<button
className="flex w-full cursor-pointer border-t-2 border-secondary-foreground p-2 pr-8"
onClick={() => {
handleForward();
}}
>
<Forward />
<p className="ml-1">Forward</p>
</button>
<ForwardDialog
ForwardedMessageId={ForwardedMessageId}
setForwardedMessageId={setForwardedMessageId}
chats={existingChats}
userInfos={userInfos}
/>

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.

Forward Functionality
2 participants