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

[front] request matchボタンからmatch をrequest する #286

Merged
merged 4 commits into from
Feb 26, 2024

Conversation

kotto5
Copy link
Collaborator

@kotto5 kotto5 commented Feb 26, 2024

  • chat side bar をコピーした
  • useRequsetMatch で修正を加えた
    • request が deny された時に button の表示に影響が出ていなかったので、useRequestMatch()で、deny のevent に対して state を変更するようにした

Copy link
Contributor

coderabbitai bot commented Feb 26, 2024

Warning

Rate Limit Exceeded

@kotto5 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 11 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 0473b49 and e73e073.

Walkthrough

The recent updates focus on enhancing user interactions in a chat application. Modifications were made to both the backend and frontend to improve how match requests are handled. The backend now directly accesses a user's WebSocket ID for denied requests, while the frontend introduces a new hook to manage match request states and updates a component to dynamically render based on the match request status. These changes streamline the process of requesting, denying, and canceling match requests, improving the overall user experience.

Changes

File Path Change Summary
backend/src/chat/.../chat.gateway.ts Modified deniedUserWsId assignment to directly access id property after calling getWsFromUserId.
frontend/app/lib/hooks/useRequestMatch.ts Added handleDenyMatchRequest function to set isRequestingMatch to false upon match request denial, triggered by "denied-match-request" event from socket.
frontend/app/ui/user/match-request-button.tsx Updated to use useRequestMatch hook for managing match requests, conditionally rendering buttons for requesting or canceling a match based on request state.

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

const requestMatch = useCallback(async () => {
setSendRequestPending(true);
socket.on("denied-match-request", handleDenyMatchRequest);
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 26, 2024

Choose a reason for hiding this comment

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

The handleDenyMatchRequest function is correctly registered as an event listener for "denied-match-request" events from the socket. This integration ensures that the UI state is updated in real-time when a match request is denied. However, it's important to ensure that this event listener is removed when the component unmounts or when it's no longer needed to prevent memory leaks and potential bugs. Consider using an effect hook to manage the lifecycle of this event listener.

+ useEffect(() => {
+   socket.on("denied-match-request", handleDenyMatchRequest);
+   return () => {
+     socket.off("denied-match-request", handleDenyMatchRequest);
+   };
+ }, [handleDenyMatchRequest]);

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.

Suggested change
socket.on("denied-match-request", handleDenyMatchRequest);
useEffect(() => {
socket.on("denied-match-request", handleDenyMatchRequest);
return () => {
socket.off("denied-match-request", handleDenyMatchRequest);
};
}, [handleDenyMatchRequest]);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

確かに!やります。
ただ、useEffect はなぜ使うの

Copy link
Contributor

Choose a reason for hiding this comment

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

@kotto5 確かに、useEffectの使用についてのご質問ありがとうございます。useEffectはReactコンポーネントのライフサイクル中に発生する副作用(例えば、APIからのデータフェッチやイベントリスナーの設定など)を扱うためのフックです。この場合、useEffectを使用する主な理由は以下の通りです:

  1. メモリリークの防止:コンポーネントがアンマウントされた後もイベントリスナーが残っていると、メモリリークを引き起こす可能性があります。useEffect内でリターンされるクリーンアップ関数を使用することで、コンポーネントのアンマウント時にイベントリスナーを適切に削除できます。

  2. 依存関係の変更への対応useEffectの第二引数に依存配列(この場合は[handleDenyMatchRequest])を渡すことで、依存する値が変更された時にのみイベントリスナーを再設定します。これにより、不要な再レンダリングを防ぎ、パフォーマンスを向上させることができます。

  3. Reactのベストプラクティスの遵守:副作用を扱う際、useEffectを使用することはReactの推奨する方法です。これにより、コンポーネントの振る舞いが予測可能で、Reactのライフサイクルイベントと一致するようになります。

以上の理由から、イベントリスナーのライフサイクル管理にuseEffectを使用することは、アプリケーションの安定性とパフォーマンスを保つ上で非常に重要です。

otherwise 関数が deny された回数呼び出される
@kotto5 kotto5 merged commit 9a1d8c0 into main Feb 26, 2024
4 checks passed
@kotto5 kotto5 deleted the feat/frontend/request-match-button branch February 26, 2024 10:43
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