Skip to content

LineBoardと駅接近通知の現在駅をヘッダーのまもなく表示に揃えて全表示面で一致させる - #6141

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

TinyKitten merged 3 commits into
devfrom
claude/approaching-station-display-jwzegb

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

概要

ヘッダーの「まもなく」は現在地基準(useApproachingStation)で次の停車駅を出す一方、LineBoard と駅接近ローカル通知は記録上の現在駅(stationState.station)基準のままでした。このため到着取りこぼし(GPS精度劣化で arrived 検知が漏れる等)時に、ヘッダーの「まもなく」駅と LineBoard の次駅・通知駅が食い違う不整合がありました。

本PRで LineBoard と駅接近通知も現在地基準に揃え、全表示面(ヘッダー / LineBoard / ライブアクティビティ・Android Live Update / Apple Watch / TTS / 駅接近通知)が常に同じ駅を指すようにします。通常運行・通過駅が間にあるケース・発車直後・ループ線では従来挙動を完全維持し、変わるのは「取りこぼし時に header と一緒に自己修復する」点のみです。

変更の種類

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

変更内容

  • 表示専用の現在地基準アクセサ useDisplayCurrentStation を追加。接近中のみ「接近駅(次の停車駅)の1つ手前の停車駅」を現在駅として返し、到着取りこぼし時に header と一緒に自己修復する。非接近・GPS無し・通常運行・ループ線では useCurrentStation() に完全フォールバックし従来挙動を維持(前方への補正が必要なときだけ healed 値を返す不変条件)
  • LineBoard 全テーマ(East / Toei / Saikyo / E231 / JRKyushu / JO / YamanotePad / West / LED)とルータ LineBoard の現在駅ソースを useDisplayCurrentStation に統一。West は既存の prevStation / currentStationIndex === -1 フォールバック挙動を保ち、前方補正時のみ追従。LED の「まもなく」テキストも useDisplayNextStation に統一
  • 駅接近ローカル通知(useRefreshStation)の接近(APPROACHING)通知の通知駅名・ターゲット判定を nearestStation → approachingStation(ヘッダーの「まもなく」と同一)に変更。発車駅除外・自己修復も反映。到着(ARRIVED)通知は「最寄り駅に到着」が正しいため nearestStation 基準のまま
  • ユニットテスト追加:useDisplayCurrentStation(非接近フォールバック / 通常運行 / 取りこぼし前方補正 / 通過駅スキップ / ループ線 / OUTBOUND)、接近通知が接近駅を通知すること、および各 LineBoard テーマのモック追従更新

テスト

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

関連Issue

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


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • 表示基準の現在駅判定ロジックを導入し、表示の一貫性を向上しました
  • Bug Fixes
    • 到着取りこぼし時に駅表示がヘッダー表示と一致するよう自動修正されるようになりました
    • 駅接近通知が現在地基準の接近駅を正確に通知するようになりました(通知送信の失敗時の安全処理を追加)
    • 各路線の駅進捗表示がヘッダー表示と連動するようになりました
  • Tests
    • 表示基準ロジックと通知挙動をカバーするテストを追加・更新しました

@TinyKitten TinyKitten self-assigned this Jun 9, 2026
@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: e3ccd768-8e99-4152-aed4-cc82b529db05

📥 Commits

Reviewing files that changed from the base of the PR and between af828cb and df11377.

📒 Files selected for processing (2)
  • src/components/LineBoardWest.test.tsx
  • src/hooks/useRefreshStation.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/LineBoardWest.test.tsx
  • src/hooks/useRefreshStation.ts

📝 Walkthrough

Walkthrough

複数の LineBoard コンポーネントで「表示基準の現在/次駅」フックに切替え、表示用に補正した現在駅を用いて駅インデックス・セル描画を統一しました。通知ロジックは接近通知と到着通知を分離し、接近駅基準で配信するよう変更しています。

Changes

Display station unification for rendering and notifications

Layer / File(s) Summary
useDisplayCurrentStation hook implementation and exports
src/hooks/useDisplayCurrentStation.ts, src/hooks/useDisplayCurrentStation.test.tsx, src/hooks/index.ts
新規フック useDisplayCurrentStation を追加。接近時に接近駅の1つ手前の停車駅へ補正(通過駅はスキップ)し、通常は既存 useCurrentStation を返す。6つの主要シナリオを含むテストを追加。
LineBoard component adoption of useDisplayCurrentStation
src/components/LineBoard*.tsx, src/components/*/*.test.tsx (複数)
LineBoard 系コンポーネント群(複数バリアント)と対応テストで、記録上の現在駅参照を useDisplayCurrentStation に置換。駅の切り出し・インデックス計算・セル状態・子コンポーネント渡し値が表示用現在駅で統一されます。
LineBoardLED adoption of useDisplayNextStation
src/components/LineBoardLED.tsx, src/components/LineBoardLED.test.tsx
LineBoardLED とそのテストで useNextStation を useDisplayNextStation に差し替え、ヘッダーの「まもなく」と表示を整合。useNextStation は型のみのインポートに変更。
useRefreshStation notification logic separation
src/hooks/useRefreshStation.ts, src/hooks/useRefreshStation.test.tsx
通知判定を「接近」と「到着」に分離。接近通知は approachingStation、到着通知は nearestStation で独立判定し、送信済みID参照で重複送信を防止するよう変更。テストで接近駅基準の通知を検証。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6138: useDisplayCurrentStation の元となる接近・次停車駅計算に関連する変更。
  • TrainLCD/MobileApp#6122: useRefreshStation に関する通知判定や到着判定のガード/整合性変更が干渉する可能性あり。

Poem

🐰 駅がちょっとズレても、僕は跳ねるよ
表示フックでぴたっと合わせるよ
接近で前へ、通過はすり抜けて
ヘッダーとボードが仲良く並んだ 🛤️
みんなで知らせる、通知もぴったり

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは「LineBoardと駅接近通知の現在駅をヘッダーのまもなく表示に揃えて全表示面で一致させる」で、PR全体の主要な変更内容(全表示面で現在駅表示を統一する)を明確に説明している。
Description check ✅ Passed テンプレートのすべての主要セクション(概要・変更の種類・変更内容・テスト実行状況)が充実して記載されており、技術的詳細も十分に説明されている。
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.

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

Actionable comments posted: 2

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

Inline comments:
In `@src/components/LineBoardWest.test.tsx`:
- Line 17: The test adds a jest mock for useDisplayCurrentStation but never
fixes its return value, so tests run with undefined; in the test file ensure in
a beforeEach you set a deterministic mock return (e.g. (useDisplayCurrentStation
as jest.Mock).mockReturnValue(...) or mockImplementation(...) with the shape the
component expects) so all assertions see a stable "current station" value, and
also clear/reset the mock in afterEach or beforeEach to avoid cross-test
leakage; apply the same pattern for the other test blocks that mock
useDisplayCurrentStation.

In `@src/hooks/useRefreshStation.ts`:
- Around line 205-217: The calls to sendApproachingNotification in the
approaching and arrived branches (where approachingNotifiedIdRef.current and
arrivedNotifiedIdRef.current are set) can produce unhandled promise rejections;
update those branches to either await sendApproachingNotification(...) inside a
try/catch or append .catch(...) to the returned promise to swallow/log errors
(e.g., use try { await sendApproachingNotification(...); } catch (e) { /* log */
} or sendApproachingNotification(...).catch(e => {/* log */})); keep the logic
that sets approachingNotifiedIdRef.current and arrivedNotifiedIdRef.current
intact and only mark the notification as delivered after handling errors as
appropriate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c767191a-9eae-4330-beb7-48fb13aedb79

📥 Commits

Reviewing files that changed from the base of the PR and between 647f3c7 and af828cb.

📒 Files selected for processing (24)
  • src/components/LineBoard.test.tsx
  • src/components/LineBoard.tsx
  • src/components/LineBoardE231.tsx
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardEast.tsx
  • src/components/LineBoardJO.test.tsx
  • src/components/LineBoardJO.tsx
  • src/components/LineBoardJRKyushu.test.tsx
  • src/components/LineBoardJRKyushu.tsx
  • src/components/LineBoardLED.test.tsx
  • src/components/LineBoardLED.tsx
  • src/components/LineBoardSaikyo.test.tsx
  • src/components/LineBoardSaikyo.tsx
  • src/components/LineBoardToei.test.tsx
  • src/components/LineBoardToei.tsx
  • src/components/LineBoardWest.test.tsx
  • src/components/LineBoardWest.tsx
  • src/components/LineBoardYamanotePad.test.tsx
  • src/components/LineBoardYamanotePad.tsx
  • src/hooks/index.ts
  • src/hooks/useDisplayCurrentStation.test.tsx
  • src/hooks/useDisplayCurrentStation.ts
  • src/hooks/useRefreshStation.test.tsx
  • src/hooks/useRefreshStation.ts

Comment thread src/components/LineBoardWest.test.tsx Resolved
Comment thread src/hooks/useRefreshStation.ts Resolved
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