mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
fix(mobile): open host editor reliably (#11635)
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
} from '../src/components/AccountUsage'
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import { loadHosts } from '../src/transport/host-store'
|
||||
import { navigateToMobileHostEdit } from '../src/transport/host-edit-navigation'
|
||||
import { removeHostAndCloseClient } from '../src/transport/host-removal-lifecycle'
|
||||
import { pickResumeWorktree } from '../src/worktree/resume-worktree'
|
||||
import type { RpcClient } from '../src/transport/rpc-client'
|
||||
@@ -1010,7 +1011,7 @@ export default function HomeScreen() {
|
||||
closeBeforePress: true,
|
||||
onPress: () => {
|
||||
setActionTarget(null)
|
||||
router.push(`/h/${host.id}/edit`)
|
||||
navigateToMobileHostEdit(router, host.id)
|
||||
}
|
||||
})
|
||||
items.push({
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { mobileHostEditRoute, navigateToMobileHostEdit } from './host-edit-navigation'
|
||||
|
||||
describe('mobileHostEditRoute', () => {
|
||||
it('keeps the dynamic host segment explicit for a cold host navigator', () => {
|
||||
expect(mobileHostEditRoute('host-1')).toEqual({
|
||||
pathname: '/h/[hostId]/edit',
|
||||
params: { hostId: 'host-1' }
|
||||
})
|
||||
})
|
||||
|
||||
it('mounts a cold host navigator before replacing its index with edit', () => {
|
||||
let nextFrame: FrameRequestCallback | null = null
|
||||
const push = vi.fn()
|
||||
const replace = vi.fn()
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
|
||||
nextFrame = callback
|
||||
return 1
|
||||
})
|
||||
|
||||
navigateToMobileHostEdit({ push, replace }, 'host-1')
|
||||
expect(push).toHaveBeenCalledWith('/h/host-1')
|
||||
expect(replace).not.toHaveBeenCalled()
|
||||
|
||||
nextFrame?.(0)
|
||||
expect(replace).toHaveBeenCalledWith(mobileHostEditRoute('host-1'))
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
type HostEditRouter = {
|
||||
push: (href: `/h/${string}`) => void
|
||||
replace: (href: ReturnType<typeof mobileHostEditRoute>) => void
|
||||
}
|
||||
|
||||
export function mobileHostEditRoute(hostId: string) {
|
||||
return {
|
||||
pathname: '/h/[hostId]/edit' as const,
|
||||
params: { hostId }
|
||||
}
|
||||
}
|
||||
|
||||
export function navigateToMobileHostEdit(router: HostEditRouter, hostId: string): void {
|
||||
// Why: a cold nested host navigator resolves a deep push to its index route.
|
||||
router.push(`/h/${hostId}`)
|
||||
requestAnimationFrame(() => {
|
||||
router.replace(mobileHostEditRoute(hostId))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user