Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions mobile/app/h/[hostId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ import { useWorkspaceSections } from '../../../src/worktree/use-workspace-sectio
import { getMobileWorkspaceLineageGroupKey } from '../../../src/worktree/mobile-workspace-lineage'
import { areWorktreeListsEqual } from '../../../src/worktree/worktree-list-snapshot'
import { repoColor } from '../../../src/worktree/repo-color'
import {
MobileCreateWorkspaceFab,
MOBILE_CREATE_WORKSPACE_FAB_LIST_CLEARANCE
} from '../../../src/worktree/MobileCreateWorkspaceFab'
import {
WORKSPACE_GROUP_OPTIONS as GROUP_OPTIONS,
WORKSPACE_SORT_OPTIONS as SORT_OPTIONS
Expand Down Expand Up @@ -1099,17 +1103,6 @@ export function HostScreen({
/>
</Pressable>

<Pressable
style={styles.newButton}
onPress={openNewWorktreeModal}
disabled={connState !== 'connected'}
>
<Plus
size={16}
color={connState === 'connected' ? colors.textPrimary : colors.textMuted}
/>
</Pressable>

<Pressable style={styles.searchToggle} onPress={() => setShowSearch((s) => !s)}>
{showSearch ? (
<X size={16} color={colors.textSecondary} />
Expand All @@ -1121,7 +1114,6 @@ export function HostScreen({
)}
</View>

{/* Auth failed banner */}
{connState === 'auth-failed' && (
<AuthFailedBanner
canRetry={!!hostId}
Expand All @@ -1131,7 +1123,6 @@ export function HostScreen({
/>
)}

{/* Search bar */}
{showSearch && (
<View style={styles.searchBar}>
<Search size={14} color={colors.textMuted} />
Expand Down Expand Up @@ -1187,7 +1178,12 @@ export function HostScreen({
// above the Samsung 3-button nav / iOS home indicator.
contentContainerStyle={[
styles.list,
{ paddingBottom: spacing.lg + insets.bottom },
{
paddingBottom:
spacing.lg +
insets.bottom +
(!embedded ? MOBILE_CREATE_WORKSPACE_FAB_LIST_CLEARANCE : 0)
},
isWideLayout &&
!embedded && { maxWidth: contentMaxWidth, width: '100%', alignSelf: 'center' }
]}
Expand Down Expand Up @@ -1245,6 +1241,14 @@ export function HostScreen({
/>
)}

{!embedded ? (
<MobileCreateWorkspaceFab
bottomOffset={insets.bottom + spacing.lg}
connected={connState === 'connected'}
onPress={openNewWorktreeModal}
/>
) : null}

<PickerModal
visible={showSortPicker}
title="Sort By"
Expand Down Expand Up @@ -1610,9 +1614,6 @@ const styles = StyleSheet.create({
toolbarIconDisabled: {
opacity: 0.6
},
newButton: {
padding: spacing.xs
},
searchToggle: {
padding: spacing.xs
},
Expand Down
65 changes: 65 additions & 0 deletions mobile/src/worktree/MobileCreateWorkspaceFab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Platform, Pressable, StyleSheet } from 'react-native'
import { Plus } from 'lucide-react-native'
import { colors, spacing } from '../theme/mobile-theme'

const MOBILE_CREATE_WORKSPACE_FAB_SIZE = 56
const MOBILE_CREATE_WORKSPACE_FAB_ICON_SIZE = 26
export const MOBILE_CREATE_WORKSPACE_FAB_LIST_CLEARANCE =
MOBILE_CREATE_WORKSPACE_FAB_SIZE + spacing.xl

type MobileCreateWorkspaceFabProps = {
bottomOffset: number
connected: boolean
onPress: () => void
}

export function MobileCreateWorkspaceFab({
bottomOffset,
connected,
onPress
}: MobileCreateWorkspaceFabProps) {
return (
<Pressable
style={[styles.button, { bottom: bottomOffset }, !connected && styles.disabled]}
onPress={onPress}
disabled={!connected}
accessibilityRole="button"
accessibilityLabel="New workspace"
accessibilityState={{ disabled: !connected }}
>
<Plus
size={MOBILE_CREATE_WORKSPACE_FAB_ICON_SIZE}
color={connected ? colors.bgBase : colors.textMuted}
/>
</Pressable>
)
}

const styles = StyleSheet.create({
button: {
position: 'absolute',
right: spacing.lg,
width: MOBILE_CREATE_WORKSPACE_FAB_SIZE,
height: MOBILE_CREATE_WORKSPACE_FAB_SIZE,
borderRadius: MOBILE_CREATE_WORKSPACE_FAB_SIZE / 2,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: colors.textPrimary,
borderWidth: 1,
borderColor: colors.borderSubtle,
zIndex: 10,
...Platform.select({
ios: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 4 },
shadowOpacity: 0.18,
shadowRadius: 12
},
android: { elevation: 8 }
})
},
disabled: {
backgroundColor: colors.bgRaised,
opacity: 0.6
}
})
38 changes: 38 additions & 0 deletions mobile/src/worktree/mobile-worktree-activation-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'

const source = readFileSync(new URL('../../app/h/[hostId]/index.tsx', import.meta.url), 'utf8')
const fabSource = readFileSync(new URL('./MobileCreateWorkspaceFab.tsx', import.meta.url), 'utf8')

function sliceBetween(startPattern: string, endPattern: string): string {
const start = source.indexOf(startPattern)
Expand All @@ -21,4 +22,41 @@ describe('mobile worktree activation', () => {
expect(openSession).toContain("sendRequest('worktree.activate'")
expect(openSession).toContain('notifyClients: false')
})

it('keeps the phone new workspace action as a bottom-right floating button', () => {
const phoneToolbar = sliceBetween(
'<View style={styles.toolbar}>',
'<Pressable style={styles.searchToggle} onPress={() => setShowSearch((s) => !s)}>'
)
const mobileCreateFabUsage = sliceBetween('{!embedded ? (', '<PickerModal')
const listPadding = sliceBetween('contentContainerStyle={[', 'renderSectionHeader=')

expect(phoneToolbar).not.toContain('openNewWorktreeModal')
expect(phoneToolbar).not.toContain('styles.newButton')

expect(mobileCreateFabUsage).toContain('<MobileCreateWorkspaceFab')
expect(mobileCreateFabUsage).toContain('bottomOffset={insets.bottom + spacing.lg}')
expect(mobileCreateFabUsage).toContain("connected={connState === 'connected'}")
expect(mobileCreateFabUsage).toContain('onPress={openNewWorktreeModal}')

expect(listPadding).toContain('!embedded ? MOBILE_CREATE_WORKSPACE_FAB_LIST_CLEARANCE : 0')
})

it('renders the mobile create workspace control as an accessible bottom-right FAB', () => {
expect(fabSource).toContain("position: 'absolute'")
expect(fabSource).toContain('right: spacing.lg')
expect(fabSource).toContain('disabled={!connected}')
expect(fabSource).toContain('accessibilityRole="button"')
expect(fabSource).toContain('accessibilityLabel="New workspace"')
expect(fabSource).toContain('accessibilityState={{ disabled: !connected }}')
expect(fabSource).toContain('Platform.select')
expect(fabSource).toContain('android: { elevation: 8 }')
})

it('preserves the embedded toolbar new workspace action', () => {
const embeddedToolbar = sliceBetween('{embedded ? (', ') : (')

expect(embeddedToolbar).toContain('onPress={openNewWorktreeModal}')
expect(embeddedToolbar).toContain('accessibilityLabel="New workspace"')
})
})
36 changes: 36 additions & 0 deletions src/renderer/src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@
them visible while pointer devices preserve the reveal-on-hover behavior. */
@custom-variant can-hover (@media (hover: hover));

.worktree-create-touch-hidden {
display: none;
}

@media (hover: hover) {
.worktree-create-touch-hidden {
display: inline-flex;
}
}

.worktree-mobile-create-fab {
display: block;
}

.worktree-mobile-create-button {
/* Why: floating action buttons escape the row surface, so they use the
documented floating elevation instead of a component-local shadow. */
box-shadow: 0 10px 24px rgb(0 0 0 / 0.18);
}

@media (hover: hover) {
.worktree-mobile-create-fab {
display: none;
}
}

.worktree-mobile-create-scroll-padding {
padding-bottom: calc(5rem + env(safe-area-inset-bottom));
}

@media (hover: hover) {
.worktree-mobile-create-scroll-padding {
padding-bottom: 0;
}
}

.theme-transition-disabled *,
.theme-transition-disabled *::before,
.theme-transition-disabled *::after {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,57 @@ describe('openWorkspaceCreationComposerWithTourHandoff', () => {
expect(requestContextualTourWhenReady).not.toHaveBeenCalled()
})

it('preserves an initial repo when opening outside the tour handoff path', () => {
const openModal = vi.fn()
vi.spyOn(useAppStore, 'getState').mockImplementation(
() =>
({
activeContextualTourId: null,
activeContextualTourStepIndex: 0,
activeContextualTourSource: null,
activeModal: 'none',
contextualToursSeenIds: [],
repos: [{ id: 'repo-1' }],
openModal
}) as unknown as ReturnType<typeof useAppStore.getState>
)

openWorkspaceCreationComposerWithTourHandoff({ initialRepoId: 'repo-1' })

expect(openModal).toHaveBeenCalledWith('new-workspace-composer', {
telemetrySource: 'sidebar',
initialRepoId: 'repo-1'
})
})

it('preserves an initial repo when opening through the handoff path', () => {
const openModal = vi.fn()
const detachContextualTourSource = vi.fn()
const completeContextualTour = vi.fn()
vi.spyOn(useAppStore, 'getState').mockImplementation(
() =>
({
activeContextualTourId: 'workspace-agent-sessions',
activeContextualTourStepIndex: 1,
activeContextualTourSource: 'setup_guide_parallel_work',
activeModal: 'none',
contextualToursSeenIds: [],
repos: [{ id: 'repo-1' }],
detachContextualTourSource,
completeContextualTour,
openModal
}) as unknown as ReturnType<typeof useAppStore.getState>
)

openWorkspaceCreationComposerWithTourHandoff({ initialRepoId: 'repo-1' })

expect(openModal).toHaveBeenCalledWith('new-workspace-composer', {
telemetrySource: 'sidebar',
initialRepoId: 'repo-1',
contextualTourSource: 'workspace_creation_modal'
})
})

it('hands off from the agent sessions create-worktree step to the workspace-creation tour', () => {
const openModal = vi.fn()
const detachContextualTourSource = vi.fn()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useAppStore } from '@/store'
import { requestContextualTourWhenReady } from './request-contextual-tour-when-ready'

export function openWorkspaceCreationComposerWithTourHandoff(): void {
export function openWorkspaceCreationComposerWithTourHandoff(
options: {
initialRepoId?: string
} = {}
): void {
const state = useAppStore.getState()
const hasProjects = state.repos.length > 0

Expand All @@ -20,6 +24,7 @@ export function openWorkspaceCreationComposerWithTourHandoff(): void {

state.openModal('new-workspace-composer', {
telemetrySource: 'sidebar',
...(options.initialRepoId ? { initialRepoId: options.initialRepoId } : {}),
...(shouldHandoffFromAgentSessionsTour
? { contextualTourSource: 'workspace_creation_modal' }
: {})
Expand Down
43 changes: 43 additions & 0 deletions src/renderer/src/components/sidebar/SidebarHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { ReactNode } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import SidebarHeader from './SidebarHeader'

const mocks = vi.hoisted(() => ({
state: {
groupBy: 'repo',
openModal: vi.fn(),
repos: [{ id: 'repo-1' }]
}
}))

vi.mock('@/store', () => ({
useAppStore: (selector: (state: typeof mocks.state) => unknown) => selector(mocks.state)
}))

vi.mock('@/hooks/useShortcutLabel', () => ({
useShortcutLabel: () => 'Ctrl+Shift+N'
}))

vi.mock('../contextual-tours/workspace-creation-tour-handoff', () => ({
openWorkspaceCreationComposerWithTourHandoff: vi.fn()
}))

vi.mock('@/components/ui/tooltip', () => ({
Tooltip: ({ children }: { children: ReactNode }) => <>{children}</>,
TooltipTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
TooltipContent: ({ children }: { children: ReactNode }) => <>{children}</>
}))

vi.mock('./SidebarWorkspaceOptionsMenu', () => ({
default: () => <button type="button">Options</button>
}))

describe('SidebarHeader', () => {
it('keeps the top workspace create button hidden on touch layouts', () => {
const markup = renderToStaticMarkup(<SidebarHeader onWorkspaceBoardMenuOpenChange={vi.fn()} />)

expect(markup).toContain('aria-label="New workspace"')
expect(markup).toContain('worktree-create-touch-hidden')
})
})
1 change: 1 addition & 0 deletions src/renderer/src/components/sidebar/SidebarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const SidebarHeader = React.memo(function SidebarHeader({
<Button
variant="ghost"
size="icon-xs"
className="worktree-create-touch-hidden"
onClick={() => {
if (!canCreateWorkspace) {
return
Expand Down
Loading