Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
26 changes: 24 additions & 2 deletions sources/app/(app)/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View, Text, Platform, Pressable, useWindowDimensions } from 'react-nati
import { Typography } from '@/constants/Typography';
import { useAllMachines, storage, useSetting } from '@/sync/storage';
import { Ionicons } from '@expo/vector-icons';
import { useRouter, useLocalSearchParams } from 'expo-router';
import { useRouter, useLocalSearchParams, useFocusEffect } from 'expo-router';
import { useUnistyles } from 'react-native-unistyles';
import { layout } from '@/components/layout';
import { t } from '@/text';
Expand Down Expand Up @@ -87,7 +87,7 @@ const updateRecentMachinePaths = (
function NewSessionScreen() {
const { theme } = useUnistyles();
const router = useRouter();
const { prompt, dataId } = useLocalSearchParams<{ prompt?: string; dataId?: string }>();
const { prompt, dataId, selectedMachineParam, selectedPathParam } = useLocalSearchParams<{ prompt?: string; dataId?: string; selectedMachineParam?: string; selectedPathParam?: string }>();

// Try to get data from temporary store first, fallback to direct prompt parameter
const tempSessionData = React.useMemo(() => {
Expand Down Expand Up @@ -202,6 +202,28 @@ function NewSessionScreen() {
};
}, []);

// Handle URL parameters from picker screens (for web compatibility)
React.useEffect(() => {
if (selectedMachineParam) {
const machine = storage.getState().machines[selectedMachineParam];
if (machine) {
setSelectedMachineId(selectedMachineParam);
const bestPath = getRecentPathForMachine(selectedMachineParam, recentMachinePaths);
setSelectedPath(bestPath);
}
// Clear the URL parameter to prevent re-processing
router.setParams({ selectedMachineParam: undefined });
}
}, [selectedMachineParam, recentMachinePaths]);

React.useEffect(() => {
if (selectedPathParam) {
setSelectedPath(selectedPathParam);
// Clear the URL parameter to prevent re-processing
router.setParams({ selectedPathParam: undefined });
}
}, [selectedPathParam]);

const handleMachineClick = React.useCallback(() => {
router.push('/new/pick/machine');
}, []);
Expand Down
3 changes: 2 additions & 1 deletion sources/app/(app)/new/pick/machine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export default function MachinePickerScreen() {

const handleSelectMachine = (machineId: string) => {
callbacks.onMachineSelected(machineId);
router.back();
// Navigate back with the selected machine ID as a parameter (for web compatibility)
router.navigate({ pathname: '/new', params: { selectedMachineParam: machineId } });
};

if (machines.length === 0) {
Expand Down
7 changes: 4 additions & 3 deletions sources/app/(app)/new/pick/path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ export default function PathPickerScreen() {

const handleSelectPath = React.useCallback(() => {
const pathToUse = customPath.trim() || machine?.metadata?.homeDir || '/home';
// Set the selection and go back
// Set the selection via callback (for native) and navigate with params (for web compatibility)
// Also pass the machineId to preserve the machine selection
callbacks.onPathSelected(pathToUse);
router.back();
}, [customPath, router, machine]);
router.navigate({ pathname: '/new', params: { selectedPathParam: pathToUse, selectedMachineParam: params.machineId } });
}, [customPath, router, machine, params.machineId]);

if (!machine) {
return (
Expand Down