Skip to content

設定モーダルに列車種別選択機能を追加 - #5673

Merged
TinyKitten merged 3 commits into
devfrom
feature/settings-train-type-modal
Mar 26, 2026
Merged

TinyKitten merged 3 commits into
devfrom
feature/settings-train-type-modal

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • SelectBoundSettingListModalに列車種別の表示・選択機能を追加
  • Main画面の長押しメニューに「設定」ボタンを追加し、設定モーダル経由で列車種別を変更可能に
  • 列車種別変更時に駅リスト・TTS状態を適切にリセットし、現在駅が新しい種別に存在しない場合は進行方向の最寄り駅にジャンプ

主な変更点

  • SelectBoundSettingListModal: 列車種別パネル(背景色付き・テキスト色自動判定)を追加
  • Permitted.tsx: 長押しActionSheetに「設定」項目を追加、TrainTypeListModalの統合
  • SelectBoundModal: 列車種別ボタンを設定モーダルに移動、ラベルを「設定・列車種別」に変更
  • CustomModal: backdrop/contentアニメーションを分離、maxWidthを400(タブレット480)に調整
  • useTTS: resetFirstSpeechAtomによる外部からのfirstSpeechリセット対応
  • GraphQL: TrainTypeRouteFragmentにcolorフィールドを追加
  • 翻訳キー追加: trainType, trainTypeDefault, settingsAndTrainType

新規ファイル

  • src/utils/findNearestStation.ts — 列車種別変更時の最寄り駅探索ロジック
  • src/utils/trainTypeTextColor.ts — 背景色に応じたテキスト色判定(polished使用)
  • テストファイル3件(31テスト追加)

Test plan

  • npm run typecheck 通過
  • npm run lint 通過
  • npm test 全1318テスト通過(新規31テスト含む)
  • 方面選択モーダルの「設定・列車種別」ボタンから列車種別を変更できること
  • Main画面の長押しメニューから設定モーダルを開き、列車種別を変更できること
  • 列車種別変更時に駅が正しく切り替わること(通過駅の場合は進行方向にジャンプ)
  • 黄色等の明るい種別色でテキストが黒になり読めること
  • 横画面でモーダルが間延びしないこと
  • タブレットでの表示確認

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 新機能

    • 列車種別セレクターを追加し、設定画面から選択可能にしました
    • 列車種別の色情報を表示できるようにしました
  • 改善

    • モーダルの表示/非表示アニメーションを同時フェード等で滑らかに最適化しました
    • 英語・日本語のUI文言を追加・更新しました
    • 音声案内の「初回発話」リセット挙動を同期的に扱うよう改善しました
  • テスト

    • 列車種別関連、最寄り駅探索、色判定、TTSリセットの単体テストを追加しました

@github-actions github-actions Bot added the react label Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

列車種別選択機能が追加され、翻訳文字列、GraphQL フラグメント型、モーダル挙動、駅探索・色判定ユーティリティ、Jotai Atom、関連コンポーネントとテスト群が更新・追加されました。

Changes

Cohort / File(s) Summary
国際化
assets/translations/en.json, assets/translations/ja.json
列車種別関連の表示文字列を追加(settingsAndTrainType, trainType, trainTypeDefault)。
GraphQL 型 / クエリ
src/@types/graphql.d.ts, src/lib/graphql/queries.ts
TrainType フラグメントに color を追加(型定義とクエリ選択セットに色情報を含める)。
モーダル共通
src/components/CustomModal.tsx
バックドロップとコンテンツで別々の Animated.Value を使用し、並列アニメーション化。タブレット向け maxWidth と maxHeight を調整。
設定モーダル UI
src/components/SelectBoundSettingListModal.tsx, src/components/SelectBoundSettingListModal.test.tsx
train-type 行(色パネル、disabled/loading 表示)と新プロップ群(onCloseAnimationEnd 等)を追加。関連テストを追加。
選択モーダル統合
src/components/SelectBoundModal.tsx
独立した列車種別ボタンを削除し、設定モーダル経由で列車種別モーダルを開く onCloseAnimationEnd/ref ベースの遷移を導入。設定ラベルを条件付きで切替。
アプリ統合(フロー制御)
src/components/Permitted.tsx
useLazyQuery(GET_LINE_GROUP_STATIONS) を統合し、列車種別選択で駅データをフェッチして stations/pendingStations 等を更新。モーダル開閉の ref ベース遷移と resetFirstSpeechAtom のインクリメントを追加。
音声制御(Jotai / フック)
src/store/atoms/speech.ts, src/hooks/useTTS.ts, src/hooks/useTTS.test.ts
新 atom resetFirstSpeechAtom を追加し、useTTS がその値変化を同期的に検出して first-speech フラグをリセットする挙動を追加。テストを更新。
色判定ユーティリティ
src/utils/trainTypeTextColor.ts, src/utils/trainTypeTextColor.test.ts
normalizeTrainTypeColor と getTrainTypeTextColor を追加(輝度判定で文字色を選択)。テスト追加。
最寄駅探索ユーティリティ
src/utils/findNearestStation.ts, src/utils/findNearestStation.test.ts
findNearestStation を追加(old/new 駅リストを比較して次の停車駅を探索)。多数の境界条件テストを追加。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Permitted as Permitted<br/>(Layout)
    participant SelectBound as SelectBound<br/>(Modal)
    participant SettingList as SelectBound<br/>SettingListModal
    participant TrainType as TrainType<br/>ListModal
    participant Apollo as Apollo<br/>GraphQL
    participant State as Jotai<br/>Atoms

    User->>Permitted: 長押しメニューを開く
    Permitted->>SelectBound: `SelectBoundModal` を表示
    User->>SelectBound: 「設定」を押す
    SelectBound->>SettingList: 設定モーダルを開く(列車種別プロップ含む)
    User->>SettingList: 列車種別行を押下
    SettingList->>SelectBound: onTrainTypePress を呼ぶ(ref フラグ設定)
    SelectBound->>SettingList: 設定モーダルを閉じる
    SettingList->>SelectBound: onCloseAnimationEnd 発火(ref チェック)
    SelectBound->>TrainType: `TrainTypeListModal` を開く
    User->>TrainType: 列車種別を選択
    TrainType->>Apollo: `GET_LINE_GROUP_STATIONS` を実行
    Apollo-->>Permitted: `lineGroupStations` を返す
    Permitted->>State: `stations` / `selectedTrainType` 更新、`resetFirstSpeechAtom` をインクリメント
    State->>Permitted: アトム変化で UI 更新
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 分

Possibly related PRs

  • TTS処理の純粋関数化 #5134 — useTTS のリファクタ(useTTS 周りを変更しているため resetFirstSpeechAtom への変更と衝突または連携の可能性あり)。

詩

🐰 新しい列車の色が光り、モーダルはふわり開く
跳ねるように駅を探し、声はまた最初から聞く
テストが網目に光り、色と方向を確かめる
小さなリセットで初声が戻り、列車は次の扉へ向かう ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「設定モーダルに列車種別選択機能を追加」で、変更内容の主要な機能追加(設定モーダルに列車種別選択機能を追加)を簡潔かつ明確に表現しており、変更セット全体の意図を正確に反映しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 feature/settings-train-type-modal

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

@TinyKitten TinyKitten self-assigned this Mar 26, 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.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/utils/findNearestStation.test.ts (1)

98-147: groupId: null の回帰テストを1本追加したいです。

Line 98-147 のエッジケースは十分ですが、Station.groupId は nullable なので、null を含む駅データで誤マッチしないことを明示的に固定しておくと安全です。

テスト追加案
 describe('エッジケース', () => {
+  it('groupId が null の駅は候補として一致させない', () => {
+    const old = [createStation(1), { ...createStation(2), groupId: null }, createStation(3)];
+    const next = [{ ...createStation(10), groupId: null }, createStation(3)];
+    const result = findNearestStation(old, next, 1, 'INBOUND');
+    expect(result?.groupId).toBe(3);
+  });
+
   it('currentGroupIdがnullの場合、nullを返す', () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/findNearestStation.test.ts` around lines 98 - 147, Add a regression
test to ensure findNearestStation does not mistakenly match stations whose
Station.groupId is null: create a test case within the existing edge-case suite
that includes a station entry with groupId: null in either localStations or
expressStations, call findNearestStation with a non-null currentGroupId (e.g.,
2) and a direction (e.g., 'INBOUND'), and assert the result is null (or the
expected non-match behavior); reference the findNearestStation function and the
test suite in src/utils/findNearestStation.test.ts when adding this case so
nullable groupId values are explicitly covered.
src/components/SelectBoundSettingListModal.test.tsx (1)

27-29: モックのクリアは afterEach に統一してください。

このリポジトリのテスト規約と揃っていません。

As per coding guidelines, **/*.test.{ts,tsx}: "Call jest.clearAllMocks() in afterEach blocks".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SelectBoundSettingListModal.test.tsx` around lines 27 - 29,
The test currently calls jest.clearAllMocks() inside a beforeEach; move that
call into an afterEach block instead to match the repository test guideline.
Specifically, remove jest.clearAllMocks() from the beforeEach in the
SelectBoundSettingListModal test suite and add an afterEach(() => {
jest.clearAllMocks(); }) so mocks are cleared after each test; leave other
beforeEach setup intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/Permitted.tsx`:
- Line 525: The current toggle using setResetFirstSpeech(prev => !prev) with
resetFirstSpeechAtom doesn't always trigger useTTS's reset because useTTS (in
useTTS.ts around the firstSpeechRef logic) only acts when the atom value is
truthy; flipping true/false causes every other call to be a no-op. Replace the
boolean flip with an event-style value: change setResetFirstSpeech to write a
monotonic counter or timestamp (e.g., increment resetFirstSpeechAtom or set it
to Date.now()) whenever you need to reset, and update useTTS to treat any change
in that atom (counter/timestamp) as the reset trigger that sets
firstSpeechRef.current = true; alternatively implement a dedicated reset action
API on the atom and invoke that action from Permitted instead of toggling the
boolean.
- Around line 490-494: fetchStationsByLineGroupId
の結果を無条件で空配列にフォールバックしてしまうと、レスポンス欠損時に stations / pendingStations / trainType
を上書きして現在の経路状態を壊します。res.data?.lineGroupStations
の存在を明示的にチェックし、存在しない(undefined/null)場合は state を更新せずに早期リターンするように修正してください(現在の
newStations = res.data?.lineGroupStations ?? [] の代わりに存在確認を行い、lineGroupStations
があるときだけ stations/pendingStations と trainType を更新する)。また
fetchStationsByLineGroupId のエラーや network failed
のケースも同様にハンドリングして状態を変更しないようにしてください。

In `@src/components/SelectBoundSettingListModal.tsx`:
- Around line 163-169: The View is assigning backgroundColor directly from the
possibly-invalid trainTypeColor, so normalize/validate the color before use and
fall back to the safe default used elsewhere; call the same color-normalization
helper you use for text (e.g., getTrainTypeTextColor() or a shared
normalizeTrainTypeColor function) and use its validated result for
backgroundColor in the styles.trainTypeNamePanel render instead of raw
trainTypeColor, preserving the existing opacity logic (trainTypeLoading ? 0.5 :
1).

In `@src/utils/findNearestStation.ts`:
- Around line 31-33: The comparison of nullable groupId values in
findNearestStation is causing false matches when both sides are null; update the
logic to skip candidates whose groupId is null (e.g., check candidateGroupId ==
null and continue) and avoid using newStations.find for repeated
lookups—pre-build a Map from newStations keyed by groupId and use that Map to
look up matches (replace the newStations.find usage that assigns found and the
similar check around lines 40-42 with Map lookups and null-groupId guards) so
only non-null, exact groupId matches are considered.

---

Nitpick comments:
In `@src/components/SelectBoundSettingListModal.test.tsx`:
- Around line 27-29: The test currently calls jest.clearAllMocks() inside a
beforeEach; move that call into an afterEach block instead to match the
repository test guideline. Specifically, remove jest.clearAllMocks() from the
beforeEach in the SelectBoundSettingListModal test suite and add an afterEach(()
=> { jest.clearAllMocks(); }) so mocks are cleared after each test; leave other
beforeEach setup intact.

In `@src/utils/findNearestStation.test.ts`:
- Around line 98-147: Add a regression test to ensure findNearestStation does
not mistakenly match stations whose Station.groupId is null: create a test case
within the existing edge-case suite that includes a station entry with groupId:
null in either localStations or expressStations, call findNearestStation with a
non-null currentGroupId (e.g., 2) and a direction (e.g., 'INBOUND'), and assert
the result is null (or the expected non-match behavior); reference the
findNearestStation function and the test suite in
src/utils/findNearestStation.test.ts when adding this case so nullable groupId
values are explicitly covered.
🪄 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: b6538bf8-738e-4764-8d7f-6a920adb95cc

📥 Commits

Reviewing files that changed from the base of the PR and between 5776fcd and 422acb8.

📒 Files selected for processing (15)
  • assets/translations/en.json
  • assets/translations/ja.json
  • src/@types/graphql.d.ts
  • src/components/CustomModal.tsx
  • src/components/Permitted.tsx
  • src/components/SelectBoundModal.tsx
  • src/components/SelectBoundSettingListModal.test.tsx
  • src/components/SelectBoundSettingListModal.tsx
  • src/hooks/useTTS.ts
  • src/lib/graphql/queries.ts
  • src/store/atoms/speech.ts
  • src/utils/findNearestStation.test.ts
  • src/utils/findNearestStation.ts
  • src/utils/trainTypeTextColor.test.ts
  • src/utils/trainTypeTextColor.ts

Comment thread src/components/Permitted.tsx Resolved
Comment thread src/components/Permitted.tsx Resolved
Comment thread src/utils/findNearestStation.ts Resolved

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

🧹 Nitpick comments (2)
src/components/Permitted.tsx (1)

490-494: ネットワークエラー時のユーザーフィードバックを検討してください。

fetchStationsByLineGroupId がネットワークエラーを返した場合、現在の実装では静かに早期リターンするだけで、ユーザーに何も通知されません。res.error をチェックしてアラートを表示することで、UX が改善できます。

♻️ 修正案
       const res = await fetchStationsByLineGroupId({
         variables: { lineGroupId: trainType.groupId },
       });
-      if (!res.data?.lineGroupStations) return;
+      if (res.error || !res.data?.lineGroupStations) {
+        if (res.error) {
+          Alert.alert(translate('errorTitle'), translate('apiErrorText'));
+        }
+        return;
+      }
       const newStations = res.data.lineGroupStations;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Permitted.tsx` around lines 490 - 494, When calling
fetchStationsByLineGroupId (the call that assigns const res = await
fetchStationsByLineGroupId(...)), add error handling for res.error before the
early return: if res.error is present, surface a user-facing alert/notification
(e.g., showToast or window.alert) with a concise message and the error.message,
then return; otherwise proceed to use res.data.lineGroupStations to set
newStations. This ensures network errors are reported instead of silently
returning.
src/utils/findNearestStation.ts (1)

29-31: 型の絞り込みを改善できます。

filter でランタイムでは正しく動作しますが、TypeScript の型絞り込みが行われないため、Map のキー型が number | null | undefined のままです。型ガードを追加することで型安全性が向上します。

♻️ 型ガードの追加案
   const newStationsByGroupId = new Map(
-    newStations.filter((s) => s.groupId != null).map((s) => [s.groupId, s])
+    newStations
+      .filter((s): s is Station & { groupId: number } => s.groupId != null)
+      .map((s) => [s.groupId, s])
   );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/findNearestStation.ts` around lines 29 - 31, The current creation
of newStationsByGroupId uses filter(s => s.groupId != null) which works at
runtime but doesn't narrow TypeScript types; change the filter to a proper type
guard so the compiler knows entries have non-null groupId (e.g., replace the
predicate with a user-defined type guard that narrows s to a type with groupId:
number), then map to [s.groupId, s] as before; update the newStationsByGroupId
initialization to use this guarded filter so the Map key type is number
(referencing newStations, the groupId property, and the newStationsByGroupId
variable).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/Permitted.tsx`:
- Around line 490-494: When calling fetchStationsByLineGroupId (the call that
assigns const res = await fetchStationsByLineGroupId(...)), add error handling
for res.error before the early return: if res.error is present, surface a
user-facing alert/notification (e.g., showToast or window.alert) with a concise
message and the error.message, then return; otherwise proceed to use
res.data.lineGroupStations to set newStations. This ensures network errors are
reported instead of silently returning.

In `@src/utils/findNearestStation.ts`:
- Around line 29-31: The current creation of newStationsByGroupId uses filter(s
=> s.groupId != null) which works at runtime but doesn't narrow TypeScript
types; change the filter to a proper type guard so the compiler knows entries
have non-null groupId (e.g., replace the predicate with a user-defined type
guard that narrows s to a type with groupId: number), then map to [s.groupId, s]
as before; update the newStationsByGroupId initialization to use this guarded
filter so the Map key type is number (referencing newStations, the groupId
property, and the newStationsByGroupId variable).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a4abec3-c93d-4710-95bf-704734211e6e

📥 Commits

Reviewing files that changed from the base of the PR and between 422acb8 and 08407e0.

📒 Files selected for processing (8)
  • src/components/Permitted.tsx
  • src/components/SelectBoundSettingListModal.test.tsx
  • src/components/SelectBoundSettingListModal.tsx
  • src/hooks/useTTS.ts
  • src/store/atoms/speech.ts
  • src/utils/findNearestStation.test.ts
  • src/utils/findNearestStation.ts
  • src/utils/trainTypeTextColor.ts
✅ Files skipped from review due to trivial changes (1)
  • src/components/SelectBoundSettingListModal.test.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/hooks/useTTS.ts
  • src/store/atoms/speech.ts
  • src/utils/trainTypeTextColor.ts
  • src/utils/findNearestStation.test.ts

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

🧹 Nitpick comments (1)
src/hooks/useTTS.test.ts (1)

340-354: この検証は呼び出し順前提で少し壊れやすいです。

Line 353 は mockClear() 後の最初の useTTSText 呼び出しが reset 起因だと仮定していますが、useTTS 側の AsyncStorage hydration でも別 rerender が入り得るので calls[0] 依存だとフレークしやすいです。reset 後の呼び出し群のどこかで firstSpeech=true が渡されたことを確認する形の方が安定します。

差分案
-    const firstCallAfterReset = useTTSText.mock.calls[0];
-    expect(firstCallAfterReset[0]).toBe(true);
+    expect(
+      useTTSText.mock.calls.some(([firstSpeech]) => firstSpeech === true)
+    ).toBe(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useTTS.test.ts` around lines 340 - 354, The current test assumes
the first call after useTTSText.mockClear() is from the reset by reading
useTTSText.mock.calls[0], which is flaky; after incrementing
resetFirstSpeechAtom via store.set(resetFirstSpeechAtom, 1) update the assertion
to check that at least one of the subsequent useTTSText.mock.calls has its first
argument true (e.g., useTTSText.mock.calls.some(call => call[0] === true)) so
the test verifies a reset-driven render passed firstSpeech=true without
depending on call order.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/hooks/useTTS.test.ts`:
- Around line 340-354: The current test assumes the first call after
useTTSText.mockClear() is from the reset by reading useTTSText.mock.calls[0],
which is flaky; after incrementing resetFirstSpeechAtom via
store.set(resetFirstSpeechAtom, 1) update the assertion to check that at least
one of the subsequent useTTSText.mock.calls has its first argument true (e.g.,
useTTSText.mock.calls.some(call => call[0] === true)) so the test verifies a
reset-driven render passed firstSpeech=true without depending on call order.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf87eb0b-cc8a-40b4-8f78-439ea428f9d8

📥 Commits

Reviewing files that changed from the base of the PR and between 08407e0 and c1e8e22.

📒 Files selected for processing (2)
  • src/hooks/useTTS.test.ts
  • src/hooks/useTTS.ts

@TinyKitten
TinyKitten merged commit 5660772 into dev Mar 26, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/settings-train-type-modal branch March 26, 2026 03:52
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