Skip to content

まもなく表示の接近駅を現在地基準で算出した実際の接近駅としアプリ・ライブアクティビティ・ウォッチ・TTS全体で次駅表示に反映 - #6135

Merged
TinyKitten merged 2 commits into
devfrom
claude/approaching-station-display-jwzegb
Jun 9, 2026

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

概要

「まもなく」表示時の接近駅を、最後に到着した駅を起点に算出する従来の次駅ではなく、GPSの現在地を起点に算出した「実際に接近している次の停車駅」に切り替えました。到着判定の取りこぼし等で次駅がずれた場合でも、接近検知・表示の双方が現在地に追従して自己修復します。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • 現在地基準で実際に接近している次の停車駅を求める useApproachingStation を追加(最寄り停車駅と次の停車駅への距離比較で、向かっている側の停車駅を返す)
  • 接近中のみ接近駅を優先し、特定不能時は従来の次駅へフォールバックする共通アクセサ useDisplayNextStation を追加
  • useRefreshStation の接近判定(isApproaching)を次駅基準から接近駅基準に変更
  • 各表示面を共通アクセサ経由で接近駅へ追従:アプリ内ヘッダー(駅名・ナンバリング)、状態判定(useStoppingState)、iOS ライブアクティビティ/Android Live Update、Apple Watch、音声読み上げ(TTS)
  • 通常運行時は接近駅=従来次駅で一致するため表示は不変。差分が出るのは現在地と記録上の現在駅がずれた場合のみで、その際は現在地基準で正しい駅へ補正される
  • 新規ユニットテスト追加(useApproachingStation / useDisplayNextStation)と、依存が変わった既存テスト(useStoppingState / useNumbering / useHeaderCommonData / useRefreshStation)のモック追従更新

ネイティブ側(Swift/Watch)は JS が送る駅情報をそのまま描画するため、JS 層の修正のみで全機能をカバーしています。

テスト

  • npm run lint が通ること
  • npm test が通ること(164 suites / 1775 tests 全パス)
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • 現在地を基準に「実際に接近している次の停車駅」を判定して表示・通知する仕組みを導入しました。
  • Tests

    • 接近判定や表示切替を網羅する複数の自動テストを追加して信頼性を高めました。
  • Refactor

    • 次駅取得・表示の参照元を統一し、「まもなく」表示時の挙動を各所で一貫化しました。

@github-actions github-actions Bot added the react label Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c7a749a-373c-4802-9565-c31044d466e7

📥 Commits

Reviewing files that changed from the base of the PR and between cafb8aa and bc8e5ce.

📒 Files selected for processing (1)
  • src/hooks/useRefreshStation.test.tsx

📝 Walkthrough

Walkthrough

GPS現在地基準で「実際に接近している次の停車駅」を算出する useApproachingStation と、接近中はそれを優先して表示用の次駅を返す useDisplayNextStation を追加し、複数の消費側フックへ統合しています。

Changes

現在地基準の接近駅判定と表示統合

Layer / File(s) Summary
接近駅判定と表示アクセサの実装
src/hooks/useApproachingStation.ts, src/hooks/useApproachingStation.test.tsx, src/hooks/useDisplayNextStation.ts, src/hooks/useDisplayNextStation.test.tsx, src/hooks/index.ts
useApproachingStation は現在地から最寄り駅を特定し、最寄りを起点に次駅を取得して距離比較で実際に接近している駅を返します。useDisplayNextStation は stationState.approaching に基づき接近駅か通常の次駅かを切り替えます。テストが座標欠損・通過駅除外・距離比較・終点等を検証します。
ヘッダー・駅番号・ウォッチ表示への統合
src/hooks/useHeaderCommonData.ts, src/hooks/useHeaderCommonData.test.tsx, src/hooks/useNumbering.ts, src/hooks/useNumbering.test.tsx, src/hooks/useAppleWatch.ts
ヘッダー共通データが displayNextStation(useDisplayNextStation)を用いて接近駅を取得し、駅番号表示・Apple Watch連携が表示用次駅を参照するようになります。テストのモックも置換されています。
状態判定と読み上げ・通知への統合
src/hooks/useStoppingState.ts, src/hooks/useStoppingState.test.tsx, src/hooks/useTTSText.ts, src/hooks/useUpdateLiveActivities.ts
停車状態判定、TTS読み上げ、ライブアクティビティ更新が useDisplayNextStation を参照するよう切り替わり、「まもなく」表示時の次駅ソースが統一されます。
リフレッシュ時の接近判定ロジック更新
src/hooks/useRefreshStation.ts, src/hooks/useRefreshStation.test.tsx
useRefreshStation が接近判定の基準を nextStation から useApproachingStation() で導出した approachingStation に変更し、approachingStation の座標欠落時は接近判定を false にするようになりました。テストでスパイと追加ケースを導入しています。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TrainLCD/MobileApp#5997: useTTSText.ts の nextStationOrigin 関連の変更点が重複しています。
  • TrainLCD/MobileApp#6122: useRefreshStation の到着/接近判定ロジック変更に関連する改修が含まれています。

Suggested labels

react

Poem

🐰 今いる場所で駅を探し、
距離をはかって次を選ぶ。
「まもなく」は現場基準、
フックたちで道をつなぎ、
今日も駅へぴょんと走る。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはPRの主要な変更内容(現在地基準の接近駅算出と全体への反映)を明確かつ具体的に要約している。
Description check ✅ Passed 提供されたテンプレートの全セクション(概要・変更種別・変更内容・テスト・関連Issue)が記入されており、詳細で実践的な情報が含まれている。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/approaching-station-display-jwzegb

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

@TinyKitten TinyKitten self-assigned this Jun 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useRefreshStation.ts (1)

147-166: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

接近判定の基準変更が approaching ステート更新に反映しきれていません

Line [147] 以降で isApproaching を approachingStation 基準にした一方、Line [267] は !getIsPass(nearestStation) を条件にしているため、最寄りが通過駅の区間で isApproaching === true でも approaching が false に潰れます。現在地基準での自己修復表示が欠落します。

修正案
-      approaching: !isArrived && !getIsPass(nearestStation) && isApproaching,
+      approaching: !isArrived && isApproaching,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useRefreshStation.ts` around lines 147 - 166, The approaching flag
update logic uses getIsPass(nearestStation) as the gate and thus clears
approaching even when isApproaching (computed from approachingStation) is true;
update the state-update condition (the code that currently checks
!getIsPass(nearestStation) around where approaching is set) to include the
isApproaching check (e.g., set approaching = true when isApproaching is true OR
when the existing nearestStation pass logic allows it) so the
approachingStation-based detection (isApproaching) can override/augment the
nearestStation pass check; target the state update block that references
getIsPass(nearestStation) and nearestStation and replace/augment its condition
with a combined check using isApproaching.
🧹 Nitpick comments (1)
src/hooks/useRefreshStation.test.tsx (1)

70-74: ⚡ Quick win

useApproachingStation を常時同一座標に固定すると新ロジックの回帰を取りこぼします

この共通セットアップだと approachingStation と nearestStation が乖離するケースを検証できず、接近基準変更の要点が未固定です。approachingStation を別駅にしたケース(特に最寄りが通過駅)を1件追加して、approaching の反映を明示的に担保してください。
As per coding guidelines, "When modifying behavior, update or add tests in the same change set" に沿って、この差分の中で新基準のズレケースを固定化するのが安全です。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useRefreshStation.test.tsx` around lines 70 - 74, 現在の共通セットアップは
useApproachingStation を常に mockStation(nearest と同座標)に固定しており、approachingStation と
nearestStation が乖離するケースを検証できません。テストファイルの useRefreshStation.test.tsx 内で
jest.spyOn(useApproachingStationModule, 'useApproachingStation')
の既存モックに加え、approachingStation を別駅(特に nearestStation
が通過駅になるシナリオ)に設定した追加ケースを作成し、useRefreshStation 呼び出し後に期待どおり approaching
の反映(state/returned value)が行われることをアサートしてください。対応箇所の識別には useApproachingStation,
approachingStation, nearestStation, mockStation を参照してください。

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/hooks/useRefreshStation.ts`:
- Around line 147-166: The approaching flag update logic uses
getIsPass(nearestStation) as the gate and thus clears approaching even when
isApproaching (computed from approachingStation) is true; update the
state-update condition (the code that currently checks
!getIsPass(nearestStation) around where approaching is set) to include the
isApproaching check (e.g., set approaching = true when isApproaching is true OR
when the existing nearestStation pass logic allows it) so the
approachingStation-based detection (isApproaching) can override/augment the
nearestStation pass check; target the state update block that references
getIsPass(nearestStation) and nearestStation and replace/augment its condition
with a combined check using isApproaching.

---

Nitpick comments:
In `@src/hooks/useRefreshStation.test.tsx`:
- Around line 70-74: 現在の共通セットアップは useApproachingStation を常に mockStation(nearest
と同座標)に固定しており、approachingStation と nearestStation が乖離するケースを検証できません。テストファイルの
useRefreshStation.test.tsx 内で jest.spyOn(useApproachingStationModule,
'useApproachingStation') の既存モックに加え、approachingStation を別駅(特に nearestStation
が通過駅になるシナリオ)に設定した追加ケースを作成し、useRefreshStation 呼び出し後に期待どおり approaching
の反映(state/returned value)が行われることをアサートしてください。対応箇所の識別には useApproachingStation,
approachingStation, nearestStation, mockStation を参照してください。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 125c4208-d6ab-4051-852f-21221a7f7bf5

📥 Commits

Reviewing files that changed from the base of the PR and between 5eedec6 and cafb8aa.

📒 Files selected for processing (16)
  • src/hooks/index.ts
  • src/hooks/useAppleWatch.ts
  • src/hooks/useApproachingStation.test.tsx
  • src/hooks/useApproachingStation.ts
  • src/hooks/useDisplayNextStation.test.tsx
  • src/hooks/useDisplayNextStation.ts
  • src/hooks/useHeaderCommonData.test.tsx
  • src/hooks/useHeaderCommonData.ts
  • src/hooks/useNumbering.test.tsx
  • src/hooks/useNumbering.ts
  • src/hooks/useRefreshStation.test.tsx
  • src/hooks/useRefreshStation.ts
  • src/hooks/useStoppingState.test.tsx
  • src/hooks/useStoppingState.ts
  • src/hooks/useTTSText.ts
  • src/hooks/useUpdateLiveActivities.ts

Copy link
Copy Markdown
Member Author

@coderabbitai レビューありがとうございます。各指摘への対応です。

① !getIsPass(nearestStation) ゲートの削除(Major)— 見送ります

このゲートは意図的な既存挙動で、今回の変更でも維持します。理由:

  • approaching は !isArrived を前提にしており、通過(isPassing = getIsPass(currentStation) && arrived)の最中は arrived === true のため、そもそも approaching は立ちません。ゲートが効くのは「駅間(未到着)かつ地理的最寄りが通過駅」という限られた区間のみで、ここで「まもなく〔次の停車駅〕」を点灯させないための抑止です。
  • 今回の本質(最後に到着した駅起点 → 現在地起点へ切り替えて次駅ずれを自己修復する)は「どの駅を出すか」の話で、ゲート(接近を出すか否か)とは直交します。純粋な自己修復シナリオ(全駅停車路線での到着取りこぼし)には通過駅が絡まないため、ゲートが自己修復をブロックすることはありません。
  • ゲートを外すと、地理的に通過駅へ最も近い区間でも「まもなく」が点灯し、通過表示と競合し得ます。スコープ外かつ回帰リスクがあるため据え置きます。

② テスト追加(Nitpick)— 対応しました

approachingStation と nearestStation が乖離するケースを src/hooks/useRefreshStation.test.tsx に追加しました(commit bc8e5ce):

  • 接近判定が次駅ではなく現在地基準の useApproachingStation を基準にすること(接近駅のみ現在地と同一座標、次駅・最寄りは遠方 → approaching === true)
  • 最寄りが通過駅のときは接近圏内でも approaching が抑止されること(①の意図的ゲートを明示的に固定)

npm run lint / npm test(164 suites / 1777 tests)/ npm run typecheck はいずれもパスしています。


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@TinyKitten ご説明ありがとうございます。

① !getIsPass(nearestStation) ゲートについて

説明いただいた内容は明確に理解しました。

  • approaching は !isArrived 前提なので、通過中(arrived === true)はそもそも立たない
  • ゲートが有効なのは「駅間かつ地理的最寄りが通過駅」という限られた区間のみ
  • 今回の自己修復シナリオ(全駅停車路線での到着取りこぼし)には通過駅が絡まないため、ゲートが機能を阻害しない

設計の意図として理解しました。据え置きの判断を尊重します。

② テスト追加について

approachingStation と nearestStation が乖離するケース、および通過駅時の approaching 抑止の両方をカバーするテストが追加された点を確認しました。対応ありがとうございます。

( ˶ᵔ ᵕ ᵔ˶ )


✏️ Learnings added
Learnt from: TinyKitten
URL: https://github.com/TrainLCD/MobileApp/pull/6135

Timestamp: 2026-06-09T03:21:30.526Z
Learning: In `src/hooks/useApproachingStation.ts` (TrainLCD/MobileApp), the `!getIsPass(nearestStation)` gate in `useApproachingStation` is intentional behavior. `approaching` requires `!isArrived` as a prerequisite, so during pass-through (`isPassing = getIsPass(currentStation) && arrived`), `arrived === true` means `approaching` never fires. The gate only takes effect in the narrow case of "between stations AND geographically nearest stop is a pass-through station", preventing "まもなく (approaching)" from activating when the nearest stop geographically is a non-stopping station. Removing this gate would cause "まもなく" to light up during pass-through segments and conflict with pass-through display. This is separate from the self-correction feature (GPS-based next station calculation), which only applies to all-stop routes where arrival detection misses occur.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@TinyKitten
TinyKitten merged commit ce2cbbf into dev Jun 9, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/approaching-station-display-jwzegb branch June 9, 2026 04:09
@TinyKitten TinyKitten mentioned this pull request Jun 9, 2026
4 of 9 tasks
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.

2 participants