fix(mobile): open resume workspace route reliably (#11876)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -50,6 +50,7 @@ import {
|
||||
type TaskProvider
|
||||
} from '../src/tasks/mobile-task-providers'
|
||||
import { useResponsiveLayout } from '../src/layout/responsive-layout'
|
||||
import { createMobileSessionHref } from '../src/session/mobile-session-route'
|
||||
|
||||
function endpointLabel(endpoint: string): string {
|
||||
try {
|
||||
@@ -807,7 +808,11 @@ export default function HomeScreen() {
|
||||
style={({ pressed }) => [styles.resumeCard, pressed && styles.hostCardPressed]}
|
||||
onPress={() =>
|
||||
router.push(
|
||||
`/h/${resumeWorktree.hostId}/session/${encodeURIComponent(resumeWorktree.worktree.worktreeId)}`
|
||||
createMobileSessionHref({
|
||||
hostId: resumeWorktree.hostId,
|
||||
worktreeId: resumeWorktree.worktree.worktreeId,
|
||||
name: resumeWorktree.worktree.displayName || resumeWorktree.worktree.repo
|
||||
})
|
||||
)
|
||||
}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createMobileSessionHref } from './mobile-session-route'
|
||||
|
||||
const homeSource = readFileSync(new URL('../../app/index.tsx', import.meta.url), 'utf8')
|
||||
|
||||
describe('mobile session route', () => {
|
||||
it('keeps dynamic route identities raw for Expo Router to encode', () => {
|
||||
expect(
|
||||
createMobileSessionHref({
|
||||
hostId: 'host/one',
|
||||
worktreeId: 'repo::/Users/ada/orca/workspaces/fix #1',
|
||||
name: 'Fix #1'
|
||||
})
|
||||
).toEqual({
|
||||
pathname: '/h/[hostId]/session/[worktreeId]',
|
||||
params: {
|
||||
hostId: 'host/one',
|
||||
worktreeId: 'repo::/Users/ada/orca/workspaces/fix #1',
|
||||
name: 'Fix #1'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('routes the home Resume card through the typed dynamic href', () => {
|
||||
const start = homeSource.indexOf('{/* ─── Resume card ─── */}')
|
||||
const end = homeSource.indexOf('{/* ─── Quick actions ─── */}', start)
|
||||
const resumeCard = homeSource.slice(start, end)
|
||||
|
||||
expect(start).toBeGreaterThanOrEqual(0)
|
||||
expect(end).toBeGreaterThan(start)
|
||||
expect(resumeCard).toContain('createMobileSessionHref({')
|
||||
expect(resumeCard).not.toContain('encodeURIComponent(resumeWorktree.worktree.worktreeId)')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
export type MobileSessionRouteParams = {
|
||||
hostId: string
|
||||
worktreeId: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
export type MobileSessionHref = {
|
||||
pathname: '/h/[hostId]/session/[worktreeId]'
|
||||
params: MobileSessionRouteParams
|
||||
}
|
||||
|
||||
export function createMobileSessionHref(params: MobileSessionRouteParams): MobileSessionHref {
|
||||
return {
|
||||
pathname: '/h/[hostId]/session/[worktreeId]',
|
||||
params
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user