Skip to content

駅検索モーダルには先に近くの駅リストを出しておく#4530

Merged
TinyKitten merged 2 commits intodevfrom
feature/search-modal-initial
Oct 30, 2025
Merged

駅検索モーダルには先に近くの駅リストを出しておく#4530
TinyKitten merged 2 commits intodevfrom
feature/search-modal-initial

Conversation

@TinyKitten
Copy link
Member

@TinyKitten TinyKitten commented Oct 30, 2025

Summary by CodeRabbit

リリースノート

  • 新機能

    • 現在地を使った周辺駅検索と駅名検索の両方に対応しました。
  • 改善

    • 駅名検索結果を優先表示するデータフローに変更しました。
    • 都道府県を含む一貫した駅ラベル表示に統一しました。
    • 周辺検索と駅名検索の読み込み/空状態表示を統合し改善しました。
    • 検索失敗時のエラーハンドリングを統合して通知を分かりやすくしました。

@TinyKitten TinyKitten self-assigned this Oct 30, 2025
@github-actions github-actions bot added the react label Oct 30, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

朕は申し述べる。StationSearchModal.tsxが位置情報に基づく近隣駅取得(GET_STATIONS_NEARBY)を追加し、useQueryによる自動近隣検索とuseLazyQueryによる名称検索を併用するデータフローへ変更された。

Changes

コホート / ファイル(s) 変更内容
駅検索モーダル — 単一ファイル更新
src/components/StationSearchModal.tsx
近隣駅の GET_STATIONS_NEARBY を追加。useLocationStore から緯度経度を取得して useQuery で近隣検索、useLazyQuery で名前検索を行う二重データソース化。GetStationsNearbyData 型導入、NEARBY_STATIONS_LIMIT と変数追加、エラーハンドリング統合、ラベル生成で groupId/id と都道府県表示を組み込み、読み込み/検索済み判定・リスト描画ロジックを更新。インポート追加と型・キー抽出の調整。

Sequence Diagram(s)

sequenceDiagram
    participant User as ユーザー
    participant Modal as StationSearchModal
    participant LocStore as useLocationStore
    participant NearbyAPI as GET_STATIONS_NEARBY
    participant NameAPI as GET_STATIONS_BY_NAME
    participant UI as 表示層

    User->>Modal: モーダルを開く
    Modal->>LocStore: 位置情報要求
    LocStore-->>Modal: 緯度・経度

    rect rgb(220,235,255)
    Note over Modal,NearbyAPI: 自動近隣検索(useQuery)
    Modal->>NearbyAPI: 緯度・経度でクエリ実行
    NearbyAPI-->>Modal: 近隣駅データ
    end

    Modal->>UI: 近隣駅を表示(初期)

    rect rgb(235,255,220)
    Note over User,NameAPI: ユーザーが駅名を検索(useLazyQuery)
    User->>Modal: 駅名入力
    Modal->>NameAPI: 名前でクエリ実行
    NameAPI-->>Modal: 名前検索結果
    end

    Modal->>UI: 名前検索結果を優先して表示(あれば)
    Note right of Modal: エラーは統合して Alert 表示
Loading

Estimated code review effort

🎯 3 (中程度) | ⏱️ ~20分

  • 注目点:
    • useLocationStore との境界と位置情報未取得時の挙動確認
    • 近隣データ型 GetStationsNearbyData と既存名検索データの整合性
    • 駅ラベル生成(groupId/id/都道府県)の重複・キー一意性

Possibly related PRs

Poem

朕、地に目を据え、駅を探す。🗺️
緯度は道を指し、名は灯を示す。✨
二つの泉より、候補は湧き、
一覧に集い、旅はまた始まる。 🚉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 朕が検討いたしたところ、このプルリクエストのタイトル「駅検索モーダルには先に近くの駅リストを出しておく」は、raw_summaryに記載される変更内容と完全に合致しておる。変更内容は、StationSearchModal.tsx に対して位置情報に基づいた近くの駅を取得する GET_STATIONS_NEARBY データフローを新たに追加し、ユーザーに近くの駅リストを優先的に表示する機能を実装するものである。タイトルはこの主要な変更点を簡潔かつ明確に表現しており、同僚がコミット履歴を眺めるだけでも、この変更の本質を即座に理解できるであろう。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/search-modal-initial

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🧹 Nitpick comments (1)
src/components/StationSearchModal.tsx (1)

140-144: エラー処理の統合は妥当である。

両クエリのエラーを統合して処理する方針は簡潔で良い。ただし、将来的にはどちらのクエリが失敗したか区別できると、より丁寧なユーザー体験となろう。現時点では問題なし。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b251c41 and 1e340df.

📒 Files selected for processing (1)
  • src/components/StationSearchModal.tsx (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.

Applied to files:

  • src/components/StationSearchModal.tsx
🧬 Code graph analysis (1)
src/components/StationSearchModal.tsx (3)
src/lib/graphql/queries.ts (2)
  • GET_STATIONS_NEARBY (273-280)
  • GET_STATIONS_BY_NAME (293-300)
src/@types/react-native-dotenv.d.ts (1)
  • NEARBY_STATIONS_LIMIT (4-4)
src/@types/graphql.d.ts (1)
  • GetStationsNearbyQueryVariables (1477-1481)
🔇 Additional comments (4)
src/components/StationSearchModal.tsx (4)

1-37: 朕、この導入と型定義を認める。

新たに追加された import と型定義は適切である。近隣駅取得のための基盤が整っておる。


175-184: 検索処理の更新、問題なし。

fetchStationsByName への移行は適切に実装されておる。


186-208: 重複除去と表示切り替えのロジック、見事である。

fetchStationsByNameCalled を基準に近隣駅と検索結果を切り替える設計は明快だ。重複除去のキー生成も、groupId → id → name+都道府県 と段階的に処理しており、朕も納得できる実装である。


255-259: 空状態の処理、適切である。

両クエリの loading 状態を統合し、fetchStationsByNameCalled で検索済みを判定する実装は正しい。モーダル表示時に近隣駅の読み込み中を示し、検索後は適切に空結果を表示する。

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)
src/components/StationSearchModal.tsx (1)

186-208: 駅リストの構築ロジックに複雑さを認める。

名称検索時と近隣駅表示時でデータソースを切り替える実装は正しいが、190-200行目の重複排除ロジックが複雑である。groupIdid、そして都道府県を含む名前によるキー生成が一つの関数内に混在しておる。

可読性を高めるため、重複排除キーの生成ロジックを別関数に抽出することを検討されよ。

例:

const getStationDeduplicationKey = (station: Station): string | number => {
  if (station.groupId) return station.groupId;
  if (station.id) return station.id;
  
  const prefId = station.prefectureId;
  if (!prefId) return station.name;
  
  return `${station.name}|${PREFECTURES_JA[prefId - 1]}`;
};

// Then in useMemo:
uniqBy(stationsByNameData?.stationsByName ?? [], getStationDeduplicationKey)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e340df and b202161.

📒 Files selected for processing (1)
  • src/components/StationSearchModal.tsx (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
PR: TrainLCD/MobileApp#4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.

Applied to files:

  • src/components/StationSearchModal.tsx
🧬 Code graph analysis (1)
src/components/StationSearchModal.tsx (3)
src/lib/graphql/queries.ts (2)
  • GET_STATIONS_NEARBY (273-280)
  • GET_STATIONS_BY_NAME (293-300)
src/@types/react-native-dotenv.d.ts (1)
  • NEARBY_STATIONS_LIMIT (4-4)
src/@types/graphql.d.ts (1)
  • GetStationsNearbyQueryVariables (1477-1481)
🔇 Additional comments (7)
src/components/StationSearchModal.tsx (7)

1-24: 輸入の追加は適切なり。

新たに追加された useQueryuseLazyQueryuseLocationStore、および関連する型定義とクエリは、近隣駅の自動取得機能を実現するために必要なものである。朕は承認する。


35-37: 型定義に誤りなし。

GetStationsNearbyData の定義は GraphQL スキーマと一致しており、朕の目に適う。


109-110: 位置情報の取得は適切なり。

useLocationStore から座標を取得する実装は問題なし。state?.coords.latitude により、state が null の場合は undefined が返されるが、120行目の skip 条件にて == null を用いることで、null と undefined の両方が適切に処理される。


115-126: 近隣駅取得の実装を承認する。

120行目の skip 条件 latitude == null || longitude == null は、null と undefined の両方を適切に判定しており、型アサーション(122-123行目)も安全に機能する。朕は満足である。


128-138: 名称検索の実装は良好なり。

useLazyQuery を用いることで、検索は利用者の操作時のみ実行される。変数名も明瞭であり、朕の統治に相応しい実装である。


140-144: エラー処理の統合を承認する。

両方のクエリのエラーを単一の Alert で処理する実装は、利用者の体験を損なわぬ賢明な判断である。


255-259: 空状態の表示ロジックを承認する。

両方のクエリのローディング状態を統合し、fetchStationsByNameCalled により検索実行の有無を判定する実装は適切である。初期表示時は近隣駅が表示され、検索後のみ「結果なし」が表示される。朕の意に適う。

@TinyKitten TinyKitten merged commit ead3065 into dev Oct 30, 2025
6 checks passed
@TinyKitten TinyKitten deleted the feature/search-modal-initial branch October 30, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant