Skip to content

経路プリセットをクイックアクションから呼び出せるようにする - #5563

Merged
TinyKitten merged 9 commits into
devfrom
feature/quick-actions-presets
Mar 10, 2026
Merged

TinyKitten merged 9 commits into
devfrom
feature/quick-actions-presets

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

Summary

close #4490

  • expo-quick-actions を導入し、SQLiteに保存された経路プリセット(最大4件)をiOS/Androidのクイックアクション(ホーム画面長押しショートカット)として表示
  • クイックアクション選択時、対応するプリセットの SelectBoundModal を自動で開く
  • iOSでは tram.fill SFSymbol アイコンを表示

主な変更

  • src/hooks/useQuickActions.ts: プリセット同期・アクション選択ハンドリングフック(新規)
  • src/store/atoms/navigation.ts: pendingQuickActionRouteId ステート追加
  • src/screens/SelectLineScreen.tsx: クイックアクション統合(同期 + 自動発火)
  • app.config.ts: expo-quick-actions プラグイン追加

動作フロー

  1. プリセット保存 → OSクイックアクションに自動反映
  2. ホーム画面でアイコン長押し → プリセット一覧表示
  3. タップ → アプリ起動 → SelectBoundModal 自動オープン

Test plan

  • iOSでホーム画面長押し → プリセットがクイックアクションに表示される
  • Androidでホーム画面長押し → プリセットがクイックアクションに表示される
  • クイックアクションタップ → SelectBoundModal が開く(コールドスタート)
  • クイックアクションタップ → SelectBoundModal が開く(ウォームスタート)
  • プリセット追加/削除でクイックアクションが更新される
  • npm run typecheck パス
  • npm test 全1261テストパス

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • クイックアクションを導入し、保存したルートへ素早く移動できるようになりました。起動時の保留アクションにも対応します。
  • 改善
    • DB初期化を一度だけ確実に行うよう安定化し、トップレベルにクイックアクション用プロバイダーを追加しました。
  • Behavior
    • 保留中のクイックアクションが該当プリセットを自動選択し、処理後に保留状態をクリアします。
  • Tests
    • クイックアクション連携のテストを追加・拡充しました。
  • Chores
    • クイックアクション用の依存パッケージを追加しました。

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

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

ネイティブのクイックアクションを追加。expo-quick-actionsを依存に追加し、useQuickActionsフックとQuickActionsProviderを導入。ナビゲーションatomにpendingQuickActionRouteIdを追加し、SelectLineScreenで保留されたクイックアクションを自動処理するロジックを追加。DB初期化に単一実行ガードを導入。

Changes

Cohort / File(s) Summary
依存関係とアプリ設定
app.config.ts, package.json
expo-quick-actions@^6.0.1をdependenciesに追加し、app.config.tsのplugins配列へ登録。
クイックアクション統合フック
src/hooks/useQuickActions.ts
新規フック。presetRoutesを最大4件でOSのクイックアクションに同期し、選択時にrouteIdを取り出してpendingQuickActionRouteIdを設定、初期アクション処理・リスナー管理・ナビゲーション待機ロジックを実装。
Provider追加とトップレベル変更
src/providers/QuickActionsProvider.tsx, src/index.tsx
QuickActionsProviderを導入しルートでラップ。アプリ起動時にuseQuickActionsを呼び出すようにプロバイダーツリーを再編。
ナビゲーション状態拡張
src/store/atoms/navigation.ts, src/hooks/*.{test,tsx}
NavigationStateに`pendingQuickActionRouteId: string
画面側の受け取りロジック
src/screens/SelectLineScreen.tsx, src/screens/SelectLineScreen.render.test.tsx
useAtomでpendingQuickActionRouteIdとsetNavigationStateを取得。usePresetCarouselDataの戻り値にroutesを追加し、保留されたrouteIdと照合して一致時にhandlePresetPressを自動実行・クリアする副作用を追加。レンダリングテストにクイックアクションのケースを追加。
保存ルートDB初期化ガード
src/hooks/useSavedRoutes.ts
SQLite初期化にinitPromise/ensureDbInitializedガードを導入し、テーブル/インデックス/列追加処理を一度だけ実行するよう変更。

Sequence Diagram(s)

sequenceDiagram
    participant OS as OS (iOS/Android)
    participant QA as QuickActions\n(useQuickActions)
    participant Nav as NavigationAtom\n(pendingQuickActionRouteId)
    participant SLS as SelectLineScreen
    participant DB as Routes Data

    OS->>QA: ユーザーがクイックアクションを選択
    QA->>QA: action.params から routeId を抽出
    QA->>Nav: pendingQuickActionRouteId を設定
    Note right of SLS: 起動済みでもコールドスタートでも処理
    SLS->>DB: usePresetCarouselData で routes を取得
    SLS->>Nav: pendingQuickActionRouteId を監視
    alt pendingQuickActionRouteId が設定されている
        SLS->>SLS: routes から一致を検索
        SLS->>SLS: handlePresetPress を呼び出す(選択処理)
        SLS->>Nav: pendingQuickActionRouteId を null にリセット
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

android

Poem

🐰✨ ホップで来たよ、クイックアクション!
ポチッと押せば道しるべが出て、
ポケットのIDがぴょんと出る、
SelectLineがふわり選んでくれる、
さあ出発、良い旅を!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはプルリクエストの主要な変更内容を正確に反映しており、クイックアクションからの経路プリセット呼び出し機能を明確に説明しています。
Linked Issues check ✅ Passed プルリクエストはリンク済みイシュー#4490の要件に対応していますが、完全なウィジェット実装ではなくクイックアクション機能を実装しており、イシューの説明との関係が明確に文書化されています。
Out of Scope Changes 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/quick-actions-presets

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

@TinyKitten TinyKitten self-assigned this Mar 10, 2026
@github-actions github-actions Bot added the ios label Mar 10, 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: 1

🧹 Nitpick comments (1)
src/screens/SelectLineScreen.render.test.tsx (1)

19-20: 新しい quick action 導線のテストがまだ通っていません。

useAtom は常に pendingQuickActionRouteId: null を返し、useQuickActions も丸ごと no-op なので、今回追加した「pending ID に一致する preset を自動で開いてからクリアする」経路が壊れてもこのファイルでは検知できません。少なくとも 1 ケース、pendingQuickActionRouteId をセットして handlePresetPress と setter の両方を確認したいです。 As per coding guidelines "Test agents in isolation and with integration tests to ensure correctness and compatibility".

Also applies to: 73-73

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

In `@src/screens/SelectLineScreen.render.test.tsx` around lines 19 - 20, The test
currently always mocks useAtom to return { pendingQuickActionRouteId: null } and
leaves useQuickActions as a no-op, so the new flow that auto-opens a preset when
pendingQuickActionRouteId is set isn't exercised; update the test to include at
least one case where useAtom returns a state with pendingQuickActionRouteId set
(e.g., a non-null ID) and a mock setter function, then assert that the component
calls handlePresetPress (or the internal opener) and that the atom setter is
called to clear the pendingQuickActionRouteId; also adjust the useQuickActions
mock to simulate the real behavior needed for auto-opening so the integration
path is tested.
🤖 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/screens/SelectLineScreen.tsx`:
- Around line 88-90: quick action handling is currently scoped to
SelectLineScreen (useQuickActions and consumption of pendingQuickActionRouteId),
so shortcuts are ignored when the app resumes on other screens; move the
quick-action listener to a global/root level (e.g., AppRoot or
NavigationContainer host) or surface a global handler via Context that consumes
pendingQuickActionRouteId and navigates to SelectLineScreen; specifically,
register useQuickActions (or its logic) at the app root, ensure it reads and
clears pendingQuickActionRouteId centrally, and invoke
navigation.navigate('SelectLineScreen', { routeId }) from that root handler so
pending shortcuts are consumed regardless of which screen is visible.

---

Nitpick comments:
In `@src/screens/SelectLineScreen.render.test.tsx`:
- Around line 19-20: The test currently always mocks useAtom to return {
pendingQuickActionRouteId: null } and leaves useQuickActions as a no-op, so the
new flow that auto-opens a preset when pendingQuickActionRouteId is set isn't
exercised; update the test to include at least one case where useAtom returns a
state with pendingQuickActionRouteId set (e.g., a non-null ID) and a mock setter
function, then assert that the component calls handlePresetPress (or the
internal opener) and that the atom setter is called to clear the
pendingQuickActionRouteId; also adjust the useQuickActions mock to simulate the
real behavior needed for auto-opening so the integration path is tested.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 43d4a43a-437b-4dc6-88bf-a51b42d8dbfc

📥 Commits

Reviewing files that changed from the base of the PR and between 17f15eb and 8054ef6.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • app.config.ts
  • package.json
  • src/hooks/useDeepLink.test.tsx
  • src/hooks/useLineSelection.test.tsx
  • src/hooks/useQuickActions.ts
  • src/screens/SelectLineScreen.render.test.tsx
  • src/screens/SelectLineScreen.tsx
  • src/store/atoms/navigation.ts

Comment thread src/screens/SelectLineScreen.tsx 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.

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/hooks/useSavedRoutes.ts`:
- Around line 124-128: The current ensureDbInitialized stores a rejected Promise
in initPromise so failures become permanent; change the assignment so
initPromise = initDb().catch(err => { initPromise = null; throw err; }) (i.e.,
in ensureDbInitialized wrap the initDb() call with a catch that resets
initPromise to null and rethrows the error) so subsequent calls can retry;
reference ensureDbInitialized, initDb, and initPromise when making this change.
- Around line 137-140: The useEffect calling ensureDbInitialized lacks error
handling and can leave presetsFetched false on rejection; wrap the promise with
a .catch (or use try/catch in an async IIFE) to capture migration/PRAGMA
failures, log the error, and update navigation atom to avoid infinite waiting —
e.g., in the catch call setNavigationAtom(prev => ({ ...prev, presetsFetched:
true, presetsInitError: true })) and include the error detail in your log (use
your app logger or console) so ensureDbInitialized, setNavigationAtom, and the
presetsFetched state are updated even on failure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7211d215-caad-440c-8122-d641e7a77a28

📥 Commits

Reviewing files that changed from the base of the PR and between 8054ef6 and d85f064.

⛔ Files ignored due to path filters (1)
  • ios/Podfile.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • src/hooks/useSavedRoutes.ts

Comment thread src/hooks/useSavedRoutes.ts Resolved
Comment thread src/hooks/useSavedRoutes.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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/hooks/useQuickActions.ts (1)

54-57: コールドスタート時のアクション処理が再マウント時に重複実行される可能性

QuickActions.initial は静的な値で、アプリが完全に再起動されるまで残り続けます。コンポーネントが再マウントされた場合、同じ initial アクションが再度処理される可能性があります。

処理済みフラグを追加するか、処理後に initial を参照しないようにすることを検討してください。

♻️ 重複処理を防ぐ修正案
+let initialHandled = false;
+
 export const useQuickActions = () => {
   // ...

   useEffect(() => {
     // ...

     // コールドスタート時
-    if (QuickActions.initial) {
+    if (QuickActions.initial && !initialHandled) {
+      initialHandled = true;
       handleAction(QuickActions.initial);
     }

     // ...
   }, [setNavigationState]);
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useQuickActions.ts` around lines 54 - 57, The cold-start action
QuickActions.initial can be processed multiple times on remount; in
useQuickActions ensure the initial action is handled only once by adding a
processed flag or clearing the static after first use: inside the initialization
logic (where QuickActions.initial is checked and
handleAction(QuickActions.initial) is called) guard it with a boolean (e.g.,
handledInitialRef or handledInitial state) or set QuickActions.initial =
null/undefined after calling handleAction, so subsequent mounts skip
re-processing; update the check and post-call behavior in useQuickActions to use
that flag/clear to prevent duplicate handling.
🤖 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/hooks/useQuickActions.ts`:
- Around line 43-51: The current navigation dispatch in useQuickActions.ts only
runs when navigationRef.isReady() is true, leaving pendingQuickActionRouteId
orphaned; change this by adopting the waitForNavReady pattern (like in
useDeepLink.ts) or by queuing/retrying the navigation when navigationRef becomes
ready: in useQuickActions.ts, wrap the dispatch logic that navigates to
'MainStack' -> 'SelectLine' (the block that checks navigationRef.isReady()) with
a waitForNavReady() helper or subscribe to navigationRef readiness, then perform
the CommonActions.navigate call and clear pendingQuickActionRouteId once
navigation succeeds; ensure the retry mechanism is idempotent so it won’t
double-navigate when already handled.

---

Nitpick comments:
In `@src/hooks/useQuickActions.ts`:
- Around line 54-57: The cold-start action QuickActions.initial can be processed
multiple times on remount; in useQuickActions ensure the initial action is
handled only once by adding a processed flag or clearing the static after first
use: inside the initialization logic (where QuickActions.initial is checked and
handleAction(QuickActions.initial) is called) guard it with a boolean (e.g.,
handledInitialRef or handledInitial state) or set QuickActions.initial =
null/undefined after calling handleAction, so subsequent mounts skip
re-processing; update the check and post-call behavior in useQuickActions to use
that flag/clear to prevent duplicate handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c53baace-bb88-45ca-b1d1-833f146271b2

📥 Commits

Reviewing files that changed from the base of the PR and between d85f064 and 5326215.

📒 Files selected for processing (5)
  • src/hooks/useQuickActions.ts
  • src/index.tsx
  • src/providers/QuickActionsProvider.tsx
  • src/screens/SelectLineScreen.render.test.tsx
  • src/screens/SelectLineScreen.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/screens/SelectLineScreen.render.test.tsx
  • src/screens/SelectLineScreen.tsx

Comment thread src/hooks/useQuickActions.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.

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/hooks/useQuickActions.ts`:
- Around line 55-64: useEffect 内で直接 QuickActions.setItems(...) を呼んで未処理の Promise
を放置しているため、QuickActions.isSupported() を使ってサポート判定を行い、setItems の呼び出しを
await/then/catch でハンドルして例外を吸収するように修正してください。具体的には useEffect のコールバックを非同期関数(または即時実行
async 関数)にして QuickActions.isSupported() を await し、true の場合のみ
QuickActions.setItems(presetRoutes.slice(0, MAX_QUICK_ACTIONS).map(...))
を呼び出し、その Promise に対して catch を追加して失敗時は無視またはログだけ残すようにしてください(参照箇所: useEffect,
QuickActions.setItems, QuickActions.isSupported, presetRoutes,
MAX_QUICK_ACTIONS, Platform.OS)。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05511fbc-61d8-43c3-b0c1-0bd7e33a1baa

📥 Commits

Reviewing files that changed from the base of the PR and between 5326215 and 7917161.

📒 Files selected for processing (2)
  • src/hooks/useQuickActions.ts
  • src/hooks/useSavedRoutes.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useSavedRoutes.ts

Comment thread src/hooks/useQuickActions.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.

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/hooks/useQuickActions.ts`:
- Around line 55-69: The current useEffect's async syncItems can run
out-of-order and overwrite newer quick-action state; modify the useQuickActions
hook to add a generation/token guard (e.g., a useRef counter or epoch) checked
by syncItems before calling QuickActions.setItems so only the latest invocation
writes to native. Increment the generation at each effect run (inside useEffect)
and capture it in syncItems; before and/or after any await, verify the captured
generation still matches the current ref and abort if not. Ensure symbols
referenced are useEffect, syncItems, QuickActions.setItems, presetRoutes, and
MAX_QUICK_ACTIONS so the fix is applied to the existing logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95fec6f5-a74d-4f72-918d-b1129b62718e

📥 Commits

Reviewing files that changed from the base of the PR and between 7917161 and 0374653.

📒 Files selected for processing (1)
  • src/hooks/useQuickActions.ts

Comment thread src/hooks/useQuickActions.ts Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Reviews resumed.

@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: 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/hooks/useQuickActions.ts`:
- Around line 15-42: The waitForNavReady() polling can give up (resolve false)
and leave pendingQuickActionRouteId set, causing stale quick actions to fire
later; update navigateToSelectLine (and the analogous block around
pendingQuickActionRouteId handling) to explicitly handle the failure case
instead of silently returning: either replace the fixed-retry polling with an
event-driven wait that subscribes to the navigation ready event (use the
navigationRef's ready/onReady listener and resolve when it fires) so it waits
until ready, or if you keep a retry limit then clear or reset
pendingQuickActionRouteId and log/handle the failure path when waitForNavReady()
returns false so no stale pending action remains. Reference:
navigateToSelectLine, waitForNavReady, navigationRef.isReady(), and
pendingQuickActionRouteId.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7dddd452-8e93-4891-9900-462de282c2c1

📥 Commits

Reviewing files that changed from the base of the PR and between 7917161 and 0374653.

📒 Files selected for processing (1)
  • src/hooks/useQuickActions.ts

Comment thread src/hooks/useQuickActions.ts Resolved
@TinyKitten
TinyKitten merged commit dbe0272 into dev Mar 10, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/quick-actions-presets branch March 10, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS/Android版ウィジェットでプリセットを選べるようにする

1 participant