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

v0.3.0 #13

Merged
merged 5 commits into from
Feb 15, 2025
Merged

v0.3.0 #13

merged 5 commits into from
Feb 15, 2025

Conversation

sweshelo
Copy link
Owner

@sweshelo sweshelo commented Feb 15, 2025

Summary by CodeRabbit

  • 新機能

    • 新たに「偏差値ランキング」ページを導入し、プレーヤーランキングの情報を表示できるようになりました。
    • 「プレーヤー検索」ページを追加。現在、準備中の状態です。
    • ドロワーメニュー機能を実装し、使いやすいナビゲーション体験を提供します。
    • プレーヤーカードに追加表示エリアを設け、柔軟な情報の配置が可能になりました。
  • リファクタリング

    • グラフの日付表示の精度を向上させ、データ表現を改善しました。
    • ヘッダーとレイアウト構成を見直し、操作性を強化しました。
  • メンテナンス

    • アプリのバージョンを0.3.0に更新しました。

Copy link
Contributor

coderabbitai bot commented Feb 15, 2025

Walkthrough

この変更は、パッケージのバージョン更新(0.2.1→0.3.0)と、複数の新規非同期ページコンポーネントおよびレイアウト改修を実施しています。具体的には、偏差値ランキングやプレーヤー検索ページの追加、Drawerコンポーネントとその状態管理機能の実装、表示ロジックの微調整、そしてSupabaseを利用したデータ取得機能の導入が行われました。

Changes

ファイル 変更内容
package.json バージョンを 0.2.1 から 0.3.0 へ更新
src/app/deviation/page.tsx, src/app/search/page.tsx, src/features/deviation/index.tsx 新しい非同期ページ関数とコンポーネント(DeviationRankingPage, プレーヤー検索ページ)を追加
src/app/layout.tsx, src/components/drawer/index.tsx, src/components/header/index.tsx, src/hooks/drawer.tsx DrawerコンポーネントとDrawerProviderの実装、HeaderのDrawer操作対応およびレイアウト改修
src/components/charts/line-chart/index.tsx 日付取得処理を created_at から recorded_at に変更
src/components/player/card.tsx PlayerCardコンポーネントに children プロパティを追加
src/service/supabase/deviation-ranking.ts Supabaseからデータを取得する新関数 fetchDeviationRanking を追加

Sequence Diagram(s)

sequenceDiagram
  participant ユーザー
  participant Page
  participant fetchDeviationRanking
  participant DeviationRankingPage
  
  ユーザー->>Page: /deviation ページにアクセス
  Page->>fetchDeviationRanking: ランキングデータをリクエスト
  fetchDeviationRanking-->>Page: データ応答
  alt ランキングデータあり
    Page->>DeviationRankingPage: コンポーネントをレンダリング
  else データなし
    Page-->>ユーザー: フォールバックメッセージ表示
  end
Loading
sequenceDiagram
  participant ユーザー
  participant Header
  participant useDrawer
  participant Drawer
  
  ユーザー->>Header: Drawerオープンボタンをクリック
  Header->>useDrawer: openDrawer を呼び出す
  useDrawer-->>Drawer: Drawerオープン状態に更新
  Drawer-->>ユーザー: Drawerを表示
Loading

Suggested labels

enhancement

Poem

ご主人様のコードに魔法が宿る
新たなページがひらりと登場✨
Drawerもすっかりおしゃれに輝く
小さな更新が未来を彩る
コードの花が優しく微笑むよ
ご主人様、輝く瞬間を共に!

✨ 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.

Copy link

vercel bot commented Feb 15, 2025

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

Name Status Preview Comments Updated (UTC)
enma-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2025 5:42am

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

🔭 Outside diff range comments (1)
src/components/player/card.tsx (1)

8-13: 🛠️ Refactor suggestion

型の改善をお手伝いさせていただきたいです!

ご主人様、FIXMEコメントで指摘されている型の問題を解決させていただきたいと思います! 以下のように型を分けることで、より分かりやすくなりそうです:

-interface PlayerCardProps {
-  player: Player | Ranking // FIXME: キモすぎるので辞めたい
-  chara: Record['chara']
-  ranking: Record['ranking']
-  children?: React.ReactElement | React.ReactElement[]
-}
+type BasePlayerCardProps = {
+  chara: Record['chara']
+  ranking: Record['ranking']
+  children?: React.ReactElement | React.ReactElement[]
+}
+
+type PlayerCardProps = BasePlayerCardProps & (
+  | { player: Player }
+  | { player: Ranking }
+)
🧹 Nitpick comments (11)
src/app/search/page.tsx (1)

1-12: 検索ページの改善提案です♪

ご主人様、シンプルな構造で分かりやすいページですね!でも、ユーザーさんのために、もう少し詳しい情報を追加してみませんか?

例えば:

  • いつ頃実装予定なのか
  • どんな検索機能が追加される予定なのか
  • 現在のステータス

などを追加すると、より親切なページになると思います🌟

src/app/deviation/page.tsx (1)

4-12: エラー処理とローディング状態の改善案です✨

ご主人様、ランキングページの実装、とても素敵ですね!でも、ユーザーさんのためにもう少し親切な表示にしてみませんか?

以下のような改善を提案させていただきます:

  • ローディング中の状態表示
  • エラーメッセージをより詳しく
  • リトライボタンの追加
 export default async function Page() {
+  // ローディング状態を管理
+  const [isLoading, setIsLoading] = useState(true)
   const ranking = await fetchDeviationRanking()
+  setIsLoading(false)

-  return ranking ? (
+  if (isLoading) return <div>ランキングを取得中です...</div>
+  
+  return ranking ? (
     <DeviationRankingPage ranking={ranking} />
   ) : (
-    <>ランキング情報の取得に失敗しました</>
+    <div className="text-center">
+      <p>ランキング情報の取得に失敗しました。</p>
+      <p className="text-sm text-gray-600">時間をおいて再度お試しください。</p>
+      <button
+        className="mt-4 px-4 py-2 bg-red-900 text-white rounded-lg"
+        onClick={() => window.location.reload()}
+      >
+        再試行
+      </button>
+    </div>
   )
 }
src/components/header/index.tsx (1)

13-16: アクセシビリティの改善提案です🎀

ご主人様、ドロワーボタンの実装、とても素敵ですね!でも、アクセシビリティをもう少し改善できそうです:

 <button
   className="w-12 h-12 bg-gray-800 rounded-lg flex items-center justify-center bg-[url('/image/icon.png')] bg-contain z-1"
   onClick={openDrawer}
+  aria-label="メニューを開く"
+  aria-expanded="false"
+  aria-controls="navigation-drawer"
 />
src/features/deviation/index.tsx (1)

19-23: パフォーマンスの改善提案です💕

ご主人様、ランキングの表示がとても分かりやすくて素敵です!でも、いくつか改善点を見つけましたので、ご提案させていただきます:

  1. keyプロパティにindexを使用するのは、要素の並び替えが発生した時に問題になる可能性があります。代わりにplayer.idを使用することをお勧めします。
  2. PlayerCardコンポーネントをメモ化すると、パフォーマンスが向上する可能性があります。
-{ranking.map((player, index) => (
-  <PlayerCard player={player} chara={player.record.chara} ranking={index + 1} key={index}>
+{ranking.map((player, index) => (
+  <PlayerCard player={player} chara={player.record.chara} ranking={index + 1} key={player.id}>
     <div className="text-sm text-gray-600 ml-1">{`| ${player.deviation_value}`}</div>
   </PlayerCard>
 ))}

メモ化の例も追加させていただきます:

const MemoizedPlayerCard = React.memo(PlayerCard)
src/components/player/card.tsx (1)

25-30: レイアウトの改善案をご提案させていただきます!

ご主人様、flexレイアウトがとても素敵ですが、スペーシングを追加すると更に見やすくなりそうです!

-        <div className="flex">
+        <div className="flex items-center gap-2">
src/service/supabase/deviation-ranking.ts (1)

16-38: パフォーマンスの改善案をご提案させていただきます!

ご主人様、現在の実装では各プレイヤーに対して個別にクエリを実行していますが、JOINを使用することでパフォーマンスを改善できそうです!

-  const playersWithRecord = await Promise.all(
-    (players ?? []).map(async player => {
-      const { data: records, error: recordError } = await supabase
-        .from('record')
-        .select('*')
-        .eq('player_name', player.name)
-        .order('created_at', { ascending: false })
-        .limit(1)
+  const { data: playersWithRecord, error: joinError } = await supabase
+    .from('player')
+    .select(`
+      *,
+      record:record(*)
+    `)
+    .gt('deviation_value', 50)
+    .order('deviation_value', { ascending: false })
+    .eq('record.player_name', 'player.name')
+    .order('record.created_at', { ascending: false })
+    .limit(1, { foreignTable: 'record' })
src/components/drawer/index.tsx (3)

13-18: アクセシビリティの改善をご提案させていただきます!

ご主人様、オーバーレイをより使いやすくするために、以下の改善をご提案させていただきます:

   <div
     className={`fixed inset-0 bg-black bg-opacity-50 transition-opacity z-[1000] ${
       isOpen ? 'opacity-100 visible' : 'opacity-0 invisible'
     }`}
     onClick={closeDrawer}
+    role="button"
+    tabIndex={0}
+    aria-label="メニューを閉じる"
+    onKeyDown={(e) => e.key === 'Escape' && closeDrawer()}
   />

21-24: アニメーションパフォーマンスの改善をご提案させていただきます!

ご主人様、transformアニメーションをより滑らかにするために、will-changeプロパティを追加すると良いかもしれません:

   className={`fixed top-0 left-0 h-full w-64 bg-white shadow-lg transform transition-transform z-[2000] ${
     isOpen ? 'translate-x-0' : '-translate-x-full'
-  }`}
+  } will-change-transform`}

35-51: アクセシビリティとSEOの改善をご提案させていただきます!

ご主人様、ナビゲーションリストにセマンティックな要素を追加すると、より良いアクセシビリティとSEOが期待できます:

-<ul className="p-4 space-y-2">
+<nav aria-label="メインメニュー">
+  <ul className="p-4 space-y-2" role="menu">
     <li>
-      <Link href="/ranking" className="block p-2 hover:bg-gray-100">
+      <Link href="/ranking" className="block p-2 hover:bg-gray-100" role="menuitem">
         ランキング
       </Link>
     </li>
     {/* 他のリンクも同様に role="menuitem" を追加 */}
   </ul>
+</nav>
src/app/layout.tsx (1)

6-8: importの順序を整理させていただきたいです〜

ご主人様、importの順序を少し整理させていただけないでしょうか?type importは他のimportの前に配置するのがベストプラクティスとされています。

このように整理させていただければと思います:

+import type { Metadata } from 'next'

import { Analytics } from '@vercel/analytics/react'
import { SpeedInsights } from '@vercel/speed-insights/next'

import { Drawer } from '@/components/drawer'
import { Header } from '@/components/header'
import { DrawerProvider } from '@/hooks/drawer'

import './globals.css'
-import type { Metadata } from 'next'

Also applies to: 11-11

src/components/charts/line-chart/index.tsx (1)

19-31: グラフの表示範囲について、ご提案がございます〜

ご主人様、現在のフィルタリング(elapsed <= 600)は適切ですが、日付範囲の制限がないため、データが増えると表示が見づらくなる可能性があります。

最近のデータ(例えば直近30日分)のみを表示するオプションを追加してはいかがでしょうか?

const DAYS_TO_SHOW = 30; // 設定可能なパラメータとして

// グループ化の前に日付でフィルタリング
const recentDate = new Date();
recentDate.setDate(recentDate.getDate() - DAYS_TO_SHOW);

const filteredRecords = records.filter(record => 
  record.elapsed && 
  record.elapsed <= 600 &&
  new Date(record.recorded_at ?? '') >= recentDate
);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55fea39 and 0240fce.

📒 Files selected for processing (11)
  • package.json (1 hunks)
  • src/app/deviation/page.tsx (1 hunks)
  • src/app/layout.tsx (2 hunks)
  • src/app/search/page.tsx (1 hunks)
  • src/components/charts/line-chart/index.tsx (1 hunks)
  • src/components/drawer/index.tsx (1 hunks)
  • src/components/header/index.tsx (1 hunks)
  • src/components/player/card.tsx (2 hunks)
  • src/features/deviation/index.tsx (1 hunks)
  • src/hooks/drawer.tsx (1 hunks)
  • src/service/supabase/deviation-ranking.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (3)
src/hooks/drawer.tsx (2)

5-9: 型定義がとても素敵ですね!

ご主人様、DrawerContextTypeの型定義がとても分かりやすくて素晴らしいです! 必要な機能がきちんと定義されていて、とても使いやすそうです♪


26-32: カスタムフックの実装が素敵です!

ご主人様、useDrawerフックのエラーメッセージがとても親切ですね!Providerの外で使用された時に分かりやすいエラーが表示されるので、他の開発者の方々も安心して使えます♪

src/app/layout.tsx (1)

54-64:

❓ Verification inconclusive

DrawerProviderの実装、とても素敵です!

ご主人様、Drawerコンポーネントの導入、とても良い改善ですね!ただ、アクセシビリティの観点から、Drawerが開いているときのキーボード操作について確認させていただきたいです。

以下の点についてご確認いただけますでしょうか?

  1. Drawerが開いているとき、Escapeキーで閉じることができますか?
  2. フォーカストラップは実装されていますか?(Drawerが開いているとき、フォーカスがDrawer内に留まるようになっていますか?)
  3. スクリーンリーダー用のARIA属性は適切に設定されていますか?

これらの実装状況を確認させていただくため、以下のスクリプトを実行させていただきます:


🏁 Script executed:

#!/bin/bash
# Drawerコンポーネントのアクセシビリティ関連実装を確認

# ARIA属性とキーボードイベントの実装を確認
rg -A 5 "aria-|role=|onKeyDown|onKeyPress" src/components/drawer/

Length of output: 67


ご主人様、Drawerコンポーネントのアクセシビリティについて再確認をお願いします

レビューでいただいた通り、Drawerが開いている際の以下の点について、現状のコードから自動検出できなかったため、手動でご確認いただくか、もしくはさらに細かい検証スクリプトの実行をお願いいたします:

  • EscapeキーでDrawerが閉じる実装
    → Drawerが開いている状態でEscapeキーのイベント処理(例: onKeyDownによるEscape検出)があるかを確認ください。

  • フォーカストラップの実装
    → Drawerが開いているときにフォーカスがDrawer内に限定される仕組みが実装されているかを確認ください。

  • ARIA属性の設定
    → スクリーンリーダー向けに、aria-*属性やroleなどの適切なアクセシビリティ属性が設定されているかを確認ください。

上記点を検証の上、必要に応じて改善をお願いいたします。

Comment on lines +12 to +14
if (playerError) {
console.error(`Error fetching player: ${playerError.message}`)
}
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

エラーハンドリングの改善をご提案させていただきます!

ご主人様、エラーをconsole.errorで出力するだけでなく、適切なエラー処理を追加すると更に安全になりそうです!

   if (playerError) {
-    console.error(`Error fetching player: ${playerError.message}`)
+    throw new Error(`プレイヤーデータの取得に失敗しました: ${playerError.message}`)
   }
📝 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
if (playerError) {
console.error(`Error fetching player: ${playerError.message}`)
}
if (playerError) {
- console.error(`Error fetching player: ${playerError.message}`)
+ throw new Error(`プレイヤーデータの取得に失敗しました: ${playerError.message}`)
}

@@ -20,7 +20,7 @@ export const PointsLineChart = ({ records }: PointsLineChartProps) => {
.filter(record => record.elapsed && record.elapsed <= 600)
.reduce<Record<string, { total: number; counts: number; records: number[] }>>(
(acc, record) => {
const date = format(new Date(record.created_at), 'yy/MM/dd')
const date = format(new Date(record.recorded_at ?? ''), 'yy/MM/dd')
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

recorded_atの扱いについて、少し気になることがございます〜

ご主人様、recorded_atフィールドがnullの場合の処理について、もう少し丁寧に扱った方が安全かもしれません。現在の実装では、nullの場合に空文字列がデフォルト値として使用されていますが、これは不適切な日付を生成する可能性があります。

以下のような修正はいかがでしょうか?

-const date = format(new Date(record.recorded_at ?? ''), 'yy/MM/dd')
+const date = record.recorded_at 
+  ? format(new Date(record.recorded_at), 'yy/MM/dd')
+  : format(new Date(), 'yy/MM/dd') // もしくは適切なデフォルト日付を設定

また、日付の妥当性チェックも追加させていただくと、より安全になりますね:

const isValidDate = (dateString: string) => {
  const date = new Date(dateString)
  return date instanceof Date && !isNaN(date.getTime())
}

@sweshelo sweshelo merged commit 7029fa8 into main Feb 15, 2025
7 checks passed
This was referenced Feb 16, 2025
@coderabbitai coderabbitai bot mentioned this pull request Feb 28, 2025
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