Skip to content

プリセットから方面選択モーダルを開いた時に両方面のカードを表示する#5584

Merged
TinyKitten merged 2 commits intodevfrom
feature/preset-both-bound-cards
Mar 11, 2026
Merged

プリセットから方面選択モーダルを開いた時に両方面のカードを表示する#5584
TinyKitten merged 2 commits intodevfrom
feature/preset-both-bound-cards

Conversation

@TinyKitten
Copy link
Member

@TinyKitten TinyKitten commented Mar 11, 2026

Summary

  • プリセットから方面選択モーダルを開いた時、wantedDestination方向のみ表示されていたのを両方面のカードを表示するように変更
  • 逆方向カードは savedRoute.direction から起点駅を特定し、正しい路線情報(ラインカラー・ナンバリング)で表示
  • プリセット区間(presetOrigin〜wantedDestination)でstopsをクリップし、GPS確定駅の座標からプリセット範囲内の最寄り中間駅を始発駅として設定
  • プリセット関連ロジックを usePresetStops カスタムフックと findNearestByCoord ユーティリティに切り出し

Key changes

  • src/utils/findNearestByCoord.ts — 座標ベースの最寄り駅検索(純粋関数)
  • src/hooks/usePresetStops.ts — presetOrigin, presetStops, nearestPresetStation, resolvePresetDirection を提供するカスタムフック
  • src/components/SelectBoundModal.tsx — インラインロジックをフックに置き換え、両方面カードの描画ロジックを追加

Test plan

  • npm run typecheck パス
  • npx biome check --unsafe --fix ./src パス
  • findNearestByCoord ユニットテスト(7件)パス
  • usePresetStops フックテスト(14件)パス
  • 日比谷線プリセット(北千住〜三ノ輪)で両方面カードが表示されること
  • サンライズ出雲プリセット(東京〜備中高梁)で経路外からも正しく動作すること
  • 東京駅でサンライズ出雲の東京方面カードが非表示になること
  • 方面を変えても始発駅が同一であること

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 新機能

    • ルート選択にプリセット停留所の判定を導入しました。保存済みルートや現在の駅・目的地に基づき出発駅・経路を自動で選定します。
    • 保存済みルートから逆方向への移動がカード操作で可能になり、往復ナビがより直感的になります。
  • テスト

    • プリセットロジックと最寄り駅判定、座標ベースの最短検索の単体テストを追加しました。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the react label Mar 11, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

保存済みルート情報と現在の駅状態を用いて開始駅・経由駅・方向を決定する新フックを導入し、SelectBoundModal の駅選択フローをpresetStops経由で拡張。座標近接検索ユーティリティが追加され、モーダルに逆方向プリセットカードを表示する変化を加えています。

Changes

Cohort / File(s) Summary
SelectBoundModal コンポーネント
src/components/SelectBoundModal.tsx
usePresetStops を導入し、handleBoundSelectedstopsOverride を追加。presetStops を考慮した停止列決定、effectiveDirection 算出、startStation 選定、wonDestination の保持ルール調整、逆方向プリセットカードの追加、レンダリング依存性拡張。
usePresetStops フック
src/hooks/usePresetStops.ts, src/hooks/usePresetStops.test.ts
新規フックを実装・公開。savedRoute.direction と stations/wantedDestination/confirmedStation から presetOrigin, presetStops, nearestPresetStation, resolvePresetDirection を導出するロジックと単体テストを追加。
座標近接ユーティリティ
src/utils/findNearestByCoord.ts, src/utils/findNearestByCoord.test.ts
findNearestByCoord を追加。緯度経度を用いて候補群から最短(二乗距離)で最近傍を選択する実装とテストを追加。null座標や空リストの扱いを含む。
フック再エクスポート
src/hooks/index.ts
usePresetStops をエクスポートに追加しパブリックに公開。
テストモック調整
src/components/SelectBoundModal.render.test.tsx
テスト内で usePresetStops のモックを追加して preset 系値を安定化。

Sequence Diagram(s)

sequenceDiagram
    participant UI as "SelectBoundModal(UI)" 
    participant Hook as "usePresetStops(hook)"
    participant Utils as "findNearestByCoord(util)"
    participant Saved as "savedRoute/context"

    rect rgba(0,120,200,0.5)
    UI->>Saved: savedRoute.direction, wantedDestination
    UI->>Hook: stations, wantedDestination, confirmedStation, savedRoute.direction
    end

    rect rgba(0,200,120,0.5)
    Hook->>Utils: if needed -> find nearest intermediate station
    Utils-->>Hook: nearestPresetStation
    Hook-->>UI: { presetOrigin, presetStops, nearestPresetStation, resolvePresetDirection }
    end

    rect rgba(200,120,0,0.5)
    UI->>UI: compute stops (stopsOverride or presetStops or stations segment)
    UI->>UI: determine effectiveDirection/startStation
    UI->>UI: update state, render bound buttons and reverse preset card
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 ふわりと跳ねるプリセットの径、
駅並びに風がそっと吹き、
緯度経度で近き友を見つけ、
モーダルは逆向きの扉も開く。
小さな改良で旅路はにっこり。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、プリセットから方面選択モーダルを開いた際に両方面のカードを表示するという主要な変更内容を正確かつ簡潔に要約しており、変更セット全体と完全に一致しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/preset-both-bound-cards

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

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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/SelectBoundModal.tsx`:
- Around line 219-229: Add a mock for usePresetStops to the jest.mock("~/hooks",
...) in SelectBoundModal.test.tsx so tests don't fail; specifically, inside that
mock export include usePresetStops: jest.fn(() => ({ presetOrigin: null,
presetStops: undefined, nearestPresetStation: undefined, resolvePresetDirection:
jest.fn(() => 'INBOUND') })), ensuring the returned object shape matches how
SelectBoundModal imports and calls usePresetStops (presetOrigin, presetStops,
nearestPresetStation, resolvePresetDirection).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7009578c-25d6-45cd-8b33-6ca52a1d1281

📥 Commits

Reviewing files that changed from the base of the PR and between f8ee83f and f942ecf.

📒 Files selected for processing (6)
  • src/components/SelectBoundModal.tsx
  • src/hooks/index.ts
  • src/hooks/usePresetStops.test.ts
  • src/hooks/usePresetStops.ts
  • src/utils/findNearestByCoord.test.ts
  • src/utils/findNearestByCoord.ts

@TinyKitten TinyKitten merged commit 6aa56ca into dev Mar 11, 2026
6 checks passed
@TinyKitten TinyKitten deleted the feature/preset-both-bound-cards branch March 11, 2026 06:31
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