Repository navigation
設定モーダルに列車種別選択機能を追加 - #5673
設定モーダルに列車種別選択機能を追加#5673
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthrough列車種別選択機能が追加され、翻訳文字列、GraphQL フラグメント型、モーダル挙動、駅探索・色判定ユーティリティ、Jotai Atom、関連コンポーネントとテスト群が更新・追加されました。 Changes
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 更新
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 分 Possibly related PRs
詩
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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}: "Calljest.clearAllMocks()inafterEachblocks".🤖 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
📒 Files selected for processing (15)
assets/translations/en.jsonassets/translations/ja.jsonsrc/@types/graphql.d.tssrc/components/CustomModal.tsxsrc/components/Permitted.tsxsrc/components/SelectBoundModal.tsxsrc/components/SelectBoundSettingListModal.test.tsxsrc/components/SelectBoundSettingListModal.tsxsrc/hooks/useTTS.tssrc/lib/graphql/queries.tssrc/store/atoms/speech.tssrc/utils/findNearestStation.test.tssrc/utils/findNearestStation.tssrc/utils/trainTypeTextColor.test.tssrc/utils/trainTypeTextColor.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (8)
src/components/Permitted.tsxsrc/components/SelectBoundSettingListModal.test.tsxsrc/components/SelectBoundSettingListModal.tsxsrc/hooks/useTTS.tssrc/store/atoms/speech.tssrc/utils/findNearestStation.test.tssrc/utils/findNearestStation.tssrc/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
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (2)
src/hooks/useTTS.test.tssrc/hooks/useTTS.ts
Summary
主な変更点
trainType,trainTypeDefault,settingsAndTrainType新規ファイル
src/utils/findNearestStation.ts— 列車種別変更時の最寄り駅探索ロジックsrc/utils/trainTypeTextColor.ts— 背景色に応じたテキスト色判定(polished使用)Test plan
npm run typecheck通過npm run lint通過npm test全1318テスト通過(新規31テスト含む)🤖 Generated with Claude Code
Summary by CodeRabbit
新機能
改善
テスト