Add ability to create new folder in host browser

This commit is contained in:
nandi committed 2026-11-18 20:06:03 -08:00
1 parent 069e1d2082
commit 0805551109
5 files changed
+158 -4

No files matched your search

+59 -1
View File
@@ -4,18 +4,22 @@ import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/ui";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useEffect, useMemo, useRef, useState } from "react";
import { Pressable, Text, View } from "react-native";
import { detectRpc, listDirRpc, openFolderRpc, pickAndOpenRpc } from "../shared/picker";
import { createFolderRpc, detectRpc, listDirRpc, openFolderRpc, pickAndOpenRpc } from "../shared/picker";
export function PickerScreen({ theme, layout, host, params, navigation }: PluginScreenProps) {
const pickAndOpen = useRpc(pickAndOpenRpc);
const openFolder = useRpc(openFolderRpc);
const detect = useRpc(detectRpc);
const listDir = useRpc(listDirRpc);
const createFolder = useRpc(createFolderRpc);
const [browserOpen, setBrowserOpen] = useState(false);
const [currentPath, setCurrentPath] = useState<string | undefined>(undefined);
const [showHidden, setShowHidden] = useState(false);
const [filter, setFilter] = useState("");
const [newFolderName, setNewFolderName] = useState("");
const [createMessage, setCreateMessage] = useState<string | null>(null);
const [createError, setCreateError] = useState<string | null>(null);
const lastTrigger = useRef<string | null>(null);
const detection = useQuery({
@@ -31,6 +35,25 @@ export function PickerScreen({ theme, layout, host, params, navigation }: Plugin
mutationFn: (path: string) => openFolder({ path }),
});
const createNewFolder = useMutation({
mutationFn: (name: string) => createFolder({ parentPath: currentPath, name }),
onSuccess: (result) => {
if (result.status === "ok") {
setNewFolderName("");
setCreateError(null);
setCreateMessage(`Created ${result.name}.`);
void directory.refetch();
} else {
setCreateMessage(null);
setCreateError(result.message);
}
},
onError: (error) => {
setCreateMessage(null);
setCreateError(error instanceof Error ? error.message : "Failed to create the folder.");
},
});
const hasGuiPicker = Boolean(detection.data?.effectivePicker);
const showBrowser = browserOpen || (detection.isSuccess && !hasGuiPicker);
@@ -44,6 +67,9 @@ export function PickerScreen({ theme, layout, host, params, navigation }: Plugin
setBrowserOpen(false);
setCurrentPath(undefined);
setFilter("");
setNewFolderName("");
setCreateMessage(null);
setCreateError(null);
lastTrigger.current = null;
}, [host.id]);
@@ -163,9 +189,13 @@ export function PickerScreen({ theme, layout, host, params, navigation }: Plugin
function navigateTo(nextPath: string) {
setFilter("");
setCreateMessage(null);
setCreateError(null);
setCurrentPath(nextPath);
}
const canCreateFolder = directory.data?.status === "ok" && Boolean(newFolderName.trim()) && !createNewFolder.isPending;
return (
<ScrollView style={styles.screen} contentContainerStyle={styles.body}>
<Text style={styles.heading}>Open a project from {host.label}</Text>
@@ -336,6 +366,34 @@ export function PickerScreen({ theme, layout, host, params, navigation }: Plugin
<Text style={styles.muted}>No subfolders match here.</Text>
) : null}
<View style={styles.row}>
<TextInput
value={newFolderName}
onChangeText={(value) => {
setNewFolderName(value);
setCreateMessage(null);
setCreateError(null);
}}
placeholder="New folder name…"
placeholderTextColor={theme.colors.foregroundMuted}
style={[styles.input, { flex: 1 }]}
/>
<Pressable
accessibilityRole="button"
accessibilityLabel="Create new folder"
style={styles.secondaryButton}
disabled={!canCreateFolder}
onPress={() => createNewFolder.mutate(newFolderName.trim())}
>
<Text style={styles.secondaryButtonText}>
{createNewFolder.isPending ? "Creating…" : "New folder"}
</Text>
</Pressable>
</View>
{createMessage ? <Text style={styles.success}>{createMessage}</Text> : null}
{createError ? <Text style={styles.error}>{createError}</Text> : null}
{filteredEntries.map((entry) => (
<View key={entry.path} style={styles.folderRow}>
<Pressable