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

Feat/frontend/online status #252

Merged
merged 5 commits into from
Feb 11, 2024
Merged

Feat/frontend/online status #252

merged 5 commits into from
Feb 11, 2024

Conversation

kotto5
Copy link
Collaborator

@kotto5 kotto5 commented Feb 11, 2024

前回、useState を使って、userのonline status を収集した
-> #248

これを用いて 実際に描画に影響させる
online だったら 緑
offline だったら 灰色になるのが goal

kakiba login 前
image

login 後
image

Copy link
Contributor

coderabbitai bot commented Feb 11, 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 29 minutes and 28 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 15990b6 and 5d86086.

Walkthrough

The recent update focuses on enhancing the application's online status management. It introduces a new OnlineProviders component that replaces the Nav component, integrates online status functionality directly within the AuthProvider, and removes the SocketProvider. A custom hook, useOnlineStatus, is added for managing online status, and the handling of online status changes now includes toast notifications. Additionally, session management functions have been updated to be asynchronous, and the user-list component now utilizes the OnlineContext for dynamic online status display.

Changes

Files Change Summary
.../app/layout.tsx Replaced Nav with OnlineProviders, removed SocketProvider, adjusted layout structure.
.../lib/client-socket-provider.tsx Added imports, refactored to accept setOnlineStatus, updated online status change handling.
.../lib/hooks/useOnlineStatus.ts Introduced useOnlineStatus hook for managing online status.
.../lib/session.ts Added "use server" directive, made setAccessToken and destroySession asynchronous.
.../app/onlineProviders.tsx Added online status information functionality, including socket provider and navigation components.
.../ui/user/user-list.tsx Replaced useState and useEffect with OnlineContext and useContext, updated online prop.

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.

@kotto5 kotto5 requested a review from usatie February 11, 2024 11:51
@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

やりたいこと
online-status を必要なcomponent (user list page) に共有したい
useContext

変えたこと
user list page に共有するには children を contextProvider のvalue で括る必要がある
online-status は useState の value なので、括る時はclient component になる。
よって、children が client component になりました。

問題
children が client component で返すようにしたのち、pageにアクセスすると白い画面のまま大量のリクエストが発生し、やがてエラーになる

image

image

@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

  • Nav component をレンダリングしなければこのエラーは起きない

上のエラー画面に、client component 内で async/await を使ってはならないと書かれている
Nav には async があるのでそれが原因か?

Nav.tsx にある async/await を削除し、Nav() が呼び出しているisLogin 等callback で呼ばれる全ての関数から async を消すと リクエストのloop はなくなり、ページが表示された

https://stackoverflow.com/questions/77078222/error-async-await-is-not-yet-supported-in-client-components-in-next-js
同じエラーメッセージに対してコードのあらゆる部分から async を消した人もいるらしいのでやってみた
信頼できるソースではない.

image

@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

session.ts が結構やばいファイルなのか?

そう感じる理由

  • import { cookies } from "next/headers"; は server component でしか利用できない
  • かといって "use server" と明示的に書くと、server component は async 関数でなければならないと怒られる

@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

今の問題

  • client component 内で async await を使えない
  • session.ts を client component 内で呼び出すと、async を使っているためループする
  • session.ts を "use server" を使って async で 全て書き直しても、変わらずループする <- いまここ

予想

  • クライアントコンポーネント以下のサーバーコンポーネントはasync を使って書けないが、"use server" と書くとエラーになるので、"use server" とは書かないようにしつつも、絶対にclient component から呼び出されないように気をつける必要がある..?

@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

解決法 予想

  • Nav bar だけ、SocketProvider (context) の外に配置する?

これ変だけど、まあ実際依存してないし解決できそう

@kotto5
Copy link
Collaborator Author

kotto5 commented Feb 11, 2024

うごいたああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ

辛かった。。。

@kotto5 kotto5 force-pushed the feat/frontend/online-status branch from e46653c to 15990b6 Compare February 11, 2024 13:02
@kotto5 kotto5 merged commit 30041ba into main Feb 11, 2024
4 checks passed
@kotto5 kotto5 deleted the feat/frontend/online-status branch February 11, 2024 14:09
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