Repository navigation
種別変更画面で経路外の路線が表示されるバグを修正 - #5715
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthrough駅一覧を基に、列車 typeId が変わる直前の駅の 変更内容
Sequence Diagram(s)sequenceDiagram
participant UI as "UI"
participant Nav as "useCurrentTrainType / navTrainType"
participant Stations as "stations"
participant TypeBox as "TrainTypeBox"
participant Notify as "TypeChangeNotify"
participant Main as "Main.updateBottomState"
UI->>Nav: 現在/次の trainType を取得
UI->>Stations: stations と selectedDirection を取得
TypeBox->>Nav: nextTrainType?.line を参照して表示判定
Notify->>Stations: selectedDirection で stations をスライス
Notify->>Stations: スライス内で typeId が変わる直前の駅を検索
Notify->>UI: 中間路線 (.line) を返す
TypeBox->>UI: 次電車表示を更新(company/id 比較)
UI->>Main: 現在状態・フラグを渡す
Main->>Main: 条件により bottomState='TYPE_CHANGE' へ早期遷移
Main-->>UI: 下部状態を更新
コード審査難易度の推定🎯 4 (Complex) | ⏱️ ~45 分 詩
🚥 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 |
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
useCurrentTrainTypeが返すtrainTypeにはlinesが含まれない場合があるため、 navigationState.trainType(fetchedTrainTypesから選択されたもの)を優先的に参照する Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/TrainTypeBox.tsx`:
- Around line 104-107: intermediateLineEntry currently uses lines?.find(l =>
l.id !== currentLine?.id) which can return a previously passed line (e.g., A
when current is B); change the logic in the useMemo so you locate the index of
currentLine in lines (using currentLine?.id) and then search only lines with a
greater index (i > currentIndex) to pick the first subsequent line; reference
the existing symbols intermediateLineEntry, useMemo, navTrainType, trainType,
currentLine and lines when making the change.
In `@src/components/TypeChangeNotify.tsx`:
- Around line 1286-1290: The current logic in displayCurrentLine (using
lines?.find to set intermediate) picks the first matching intermediate line and
thus returns the upstream/first one in multi-intermediate routes; instead
restrict the search to lines strictly between currentLine and nextLine and
return the one closest to nextLine (i.e., the last matching intermediate).
Replace the lines?.find(...) usage with logic that locates the slice/range
between currentLine and nextLine (using their indices in lines from navTrainType
or trainType) and pick the last element in that range as intermediate, ensuring
variables referenced are navTrainType, trainType, lines, currentLine, nextLine,
and intermediate (falling back to currentLine if none).
🪄 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: 7bb2e9ca-3fe0-47b1-812d-96f8ce60ee37
📒 Files selected for processing (2)
src/components/TrainTypeBox.tsxsrc/components/TypeChangeNotify.tsx
trainType.linesに小田急多摩線・小田急小田原線等の同一会社路線が含まれる場合、 路線IDでの除外では小田急小田原線が先にヒットしてしまうため、 会社IDで比較して同一会社の路線をスキップするように修正 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
867b35e to
b0f693b
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/components/TrainTypeBox.tsx (1)
103-108:⚠️ Potential issue | 🟠 Major会社ID比較だけでは逆側の路線誤選択を防げません。
Line 106 の
find()は先頭から固定で走るので、trainType.lines = [小田急多摩, 小田急小田原, 千代田, 常磐]で現在が千代田のときに小田急側を拾えます。currentLineの位置とselectedDirectionを基準に、進行方向側だけを候補にしないと線内表示がまだ過去側へ戻ります。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/TrainTypeBox.tsx` around lines 103 - 108, The current intermediateLineEntry useMemo picks the first line with a different company.id, which can choose a line behind the current position; update the logic to compute the index of currentLine within (navTrainType?.lines ?? trainType?.lines), then filter candidate lines to only those on the selectedDirection side (e.g., indices greater than currentIndex for forward, less for backward) before calling find by company id; modify the useMemo block that defines intermediateLineEntry to use currentIndex, selectedDirection and a directional filter so only forward-facing lines are considered when locating a different company.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/components/TrainTypeBox.tsx`:
- Around line 103-108: The current intermediateLineEntry useMemo picks the first
line with a different company.id, which can choose a line behind the current
position; update the logic to compute the index of currentLine within
(navTrainType?.lines ?? trainType?.lines), then filter candidate lines to only
those on the selectedDirection side (e.g., indices greater than currentIndex for
forward, less for backward) before calling find by company id; modify the
useMemo block that defines intermediateLineEntry to use currentIndex,
selectedDirection and a directional filter so only forward-facing lines are
considered when locating a different company.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7a9c9410-6c9d-437c-afa2-09274a02792d
📒 Files selected for processing (4)
src/components/TrainTypeBox.tsxsrc/components/TypeChangeNotify.test.tsxsrc/components/TypeChangeNotify.tsxsrc/screens/Main.tsx
✅ Files skipped from review due to trivial changes (1)
- src/screens/Main.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
- src/components/TypeChangeNotify.tsx
- src/components/TypeChangeNotify.test.tsx
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/TrainTypeBox.tsx`:
- Around line 246-252: showNextTrainType currently only checks for
nextTrainType?.line and compares currentLine?.company?.id to
nextTrainType.line.company?.id, so when company or its name fields
(nameEnglishShort/nameShort) are undefined you render "undefined…" in the
template; fix by deriving a safe displayCompanyName from
nextTrainType.line.company (e.g., prefer nameEnglishShort, then nameShort, then
null) and use that in the useMemo condition and in the render: update the
useMemo (showNextTrainType) to require a non-null displayCompanyName and
nextTrainType?.line, and change the template usage to use the displayCompanyName
(or hide the whole fragment when null) so you never interpolate undefined
company names; reference symbols: showNextTrainType, nextTrainType, currentLine,
nameEnglishShort, nameShort, and the hook useNextTrainType.
🪄 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: 8169bec7-6282-4183-a0db-75ea7b6b6a3e
📒 Files selected for processing (1)
src/components/TrainTypeBox.tsx
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/TrainTypeBox.tsx`:
- Around line 246-259: nextTrainTypeCompanyName is computed but not used in the
render, and the render directly reads company.nameEnglishShort / nameShort which
causes "undefined" in EN mode when only nameShort exists; update the code to
consistently derive a language-aware company name and use it both for visibility
and rendering: replace the current nextTrainTypeCompanyName with a
language-specific value (e.g., pick company.nameEnglishShort when in English
mode else company.nameShort), use that value in the showNextTrainType boolean
(alongside nextTrainType and currentLine company id checks), and update the
render portion that currently reads company.nameEnglishShort/nameShort to render
nextTrainTypeCompanyName (with a final null/empty fallback), ensuring
nextTrainType, nextTrainTypeCompanyName, showNextTrainType and currentLine
comparisons remain in dependencies.
🪄 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: 4645ed23-b9eb-4a59-a86d-1ff3b4e86194
📒 Files selected for processing (1)
src/components/TrainTypeBox.tsx
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Summary
nextTrainTypeから直接取得するように修正変更内容
TypeChangeNotify (
src/components/TypeChangeNotify.tsx)displayCurrentLineの算出ロジックを、種別が変わる直前の駅のs.lineを参照する方式に変更s.lines(駅に紐づく全路線配列)から検索 → 常磐快速線等の経路外路線が混入する問題があったstations配列で次の種別に変わる直前の駅を特定し、そのlineプロパティを使用TrainTypeBox (
src/components/TrainTypeBox.tsx)intermediateLineEntry(trainType.linesベース)を廃止し、nextTrainTypeを直接参照するように変更nextTrainType.line?.companyで会社名、nextTrainType.nameで種別名を取得Main (
src/screens/Main.tsx)updateBottomStateでtransferLinesが0件の場合でもisTypeWillChangeならTYPE_CHANGEに直接遷移するように修正Test plan
npm run typecheck✅npm run lint✅npm test✅🤖 Generated with Claude Code
Summary by CodeRabbit
変更内容
バグ修正
テスト