feat: add direct path input bar to Files page and FileBrowserModal
This commit is contained in:
@@ -41,6 +41,8 @@ export default function FileBrowserModal({ initialPath, onSelect, onClose }: Pro
|
|||||||
const [mkdirName, setMkdirName] = useState("");
|
const [mkdirName, setMkdirName] = useState("");
|
||||||
const [renameState, setRenameState] = useState<{ path: string; name: string } | null>(null);
|
const [renameState, setRenameState] = useState<{ path: string; name: string } | null>(null);
|
||||||
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
const [selectedPath, setSelectedPath] = useState<string | null>(null);
|
||||||
|
const [pathInput, setPathInput] = useState(currentPath);
|
||||||
|
const [editingPath, setEditingPath] = useState(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const LIMIT = 200;
|
const LIMIT = 200;
|
||||||
|
|
||||||
@@ -58,6 +60,10 @@ export default function FileBrowserModal({ initialPath, onSelect, onClose }: Pro
|
|||||||
loadDir(currentPath, 1);
|
loadDir(currentPath, 1);
|
||||||
}, [currentPath]);
|
}, [currentPath]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!editingPath) setPathInput(currentPath);
|
||||||
|
}, [currentPath, editingPath]);
|
||||||
|
|
||||||
async function loadDir(path: string, pageNum: number) {
|
async function loadDir(path: string, pageNum: number) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -88,6 +94,21 @@ export default function FileBrowserModal({ initialPath, onSelect, onClose }: Pro
|
|||||||
setSelectedPath(null);
|
setSelectedPath(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleNavigateToPath(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
const path = pathInput.trim() || "/";
|
||||||
|
try {
|
||||||
|
const info = await api.fileInfo(path);
|
||||||
|
if (!info.is_dir) {
|
||||||
|
setError("La ruta no es un directorio");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigateTo(path);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Ruta no accesible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleDoubleClick(entry: FileEntry) {
|
function handleDoubleClick(entry: FileEntry) {
|
||||||
if (entry.is_dir) {
|
if (entry.is_dir) {
|
||||||
navigateTo(entry.path);
|
navigateTo(entry.path);
|
||||||
@@ -153,11 +174,6 @@ export default function FileBrowserModal({ initialPath, onSelect, onClose }: Pro
|
|||||||
return "/" + parts.join("/");
|
return "/" + parts.join("/");
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const breadcrumbs = currentPath.split("/").filter(Boolean).map((part, i, arr) => {
|
|
||||||
const path = "/" + arr.slice(0, i + 1).join("/");
|
|
||||||
return { part, path };
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal title="Explorar directorio" onClose={onClose} maxWidth="4xl">
|
<Modal title="Explorar directorio" onClose={onClose} maxWidth="4xl">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
@@ -177,14 +193,24 @@ export default function FileBrowserModal({ initialPath, onSelect, onClose }: Pro
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
)}
|
)}
|
||||||
<div className="flex items-center gap-1 text-sm text-slate-300">
|
<div className="flex items-center gap-1 text-sm text-slate-300 flex-1 min-w-0">
|
||||||
<button className="btn-ghost px-2 py-1 text-xs" onClick={() => parentDir && navigateTo(parentDir)} disabled={!parentDir}>↑</button>
|
<button className="btn-ghost px-2 py-1 text-xs" onClick={() => parentDir && navigateTo(parentDir)} disabled={!parentDir}>←</button>
|
||||||
{breadcrumbs.map((b, i) => (
|
<form onSubmit={handleNavigateToPath} className="flex-1 min-w-0">
|
||||||
<span key={i} className="flex items-center">
|
<input
|
||||||
<button className="hover:text-white" onClick={() => navigateTo(b.path)}>{b.part}</button>
|
className="input font-mono text-sm w-full"
|
||||||
{i < breadcrumbs.length - 1 && <span className="mx-1 text-slate-600">/</span>}
|
value={pathInput}
|
||||||
</span>
|
placeholder="/ruta/absoluta"
|
||||||
))}
|
onFocus={() => setEditingPath(true)}
|
||||||
|
onBlur={() => { setEditingPath(false); setPathInput(currentPath); }}
|
||||||
|
onChange={e => setPathInput(e.target.value)}
|
||||||
|
onKeyDown={e => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setPathInput(currentPath);
|
||||||
|
(e.target as HTMLInputElement).blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+39
-12
@@ -44,6 +44,9 @@ export default function Files() {
|
|||||||
const [searchResults, setSearchResults] = useState<SearchHit[]>([]);
|
const [searchResults, setSearchResults] = useState<SearchHit[]>([]);
|
||||||
const [searching, setSearching] = useState(false);
|
const [searching, setSearching] = useState(false);
|
||||||
|
|
||||||
|
const [pathInput, setPathInput] = useState(currentPath);
|
||||||
|
const [editingPath, setEditingPath] = useState(false);
|
||||||
|
|
||||||
const [showMkdir, setShowMkdir] = useState(false);
|
const [showMkdir, setShowMkdir] = useState(false);
|
||||||
const [mkdirName, setMkdirName] = useState("");
|
const [mkdirName, setMkdirName] = useState("");
|
||||||
|
|
||||||
@@ -86,6 +89,10 @@ export default function Files() {
|
|||||||
setSearchQuery("");
|
setSearchQuery("");
|
||||||
}, [currentPath]);
|
}, [currentPath]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!editingPath) setPathInput(currentPath);
|
||||||
|
}, [currentPath, editingPath]);
|
||||||
|
|
||||||
async function loadDir(path: string, pageNum: number) {
|
async function loadDir(path: string, pageNum: number) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -118,6 +125,21 @@ export default function Files() {
|
|||||||
setCurrentPath(path);
|
setCurrentPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleNavigateToPath(e: React.FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
const path = pathInput.trim() || "/";
|
||||||
|
try {
|
||||||
|
const info = await api.fileInfo(path);
|
||||||
|
if (!info.is_dir) {
|
||||||
|
setError("La ruta no es un directorio");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigateTo(path);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Ruta no accesible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleDoubleClick(entry: FileEntry) {
|
function handleDoubleClick(entry: FileEntry) {
|
||||||
if (entry.is_dir) {
|
if (entry.is_dir) {
|
||||||
navigateTo(entry.path);
|
navigateTo(entry.path);
|
||||||
@@ -148,11 +170,6 @@ export default function Files() {
|
|||||||
return parent === "/" ? "/" : parent;
|
return parent === "/" ? "/" : parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const breadcrumbs = currentPath.split("/").filter(Boolean).map((part, i, arr) => {
|
|
||||||
const path = "/" + arr.slice(0, i + 1).join("/");
|
|
||||||
return { part, path };
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleMkdir() {
|
async function handleMkdir() {
|
||||||
if (!mkdirName.trim()) return;
|
if (!mkdirName.trim()) return;
|
||||||
try {
|
try {
|
||||||
@@ -305,18 +322,28 @@ export default function Files() {
|
|||||||
Sin restricción — acceso a todo el FS
|
Sin restricción — acceso a todo el FS
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<div className="flex items-center gap-1 text-sm text-slate-300 flex-1 min-w-0">
|
<div className="flex items-center gap-2 text-sm text-slate-300 flex-1 min-w-0">
|
||||||
<button
|
<button
|
||||||
className="btn-ghost px-2 py-1 text-xs"
|
className="btn-ghost px-2 py-1 text-xs"
|
||||||
onClick={() => parentDir() && navigateTo(parentDir()!)}
|
onClick={() => parentDir() && navigateTo(parentDir()!)}
|
||||||
disabled={!parentDir()}
|
disabled={!parentDir()}
|
||||||
>←</button>
|
>←</button>
|
||||||
{breadcrumbs.map((b, i) => (
|
<form onSubmit={handleNavigateToPath} className="flex-1 min-w-0">
|
||||||
<span key={i} className="flex items-center">
|
<input
|
||||||
<button className="hover:text-white truncate max-w-32" onClick={() => navigateTo(b.path)}>{b.part}</button>
|
className="input font-mono text-sm w-full"
|
||||||
{i < breadcrumbs.length - 1 && <span className="mx-1 text-slate-600">/</span>}
|
value={pathInput}
|
||||||
</span>
|
placeholder="/ruta/absoluta"
|
||||||
))}
|
onFocus={() => setEditingPath(true)}
|
||||||
|
onBlur={() => { setEditingPath(false); setPathInput(currentPath); }}
|
||||||
|
onChange={e => setPathInput(e.target.value)}
|
||||||
|
onKeyDown={e => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setPathInput(currentPath);
|
||||||
|
(e.target as HTMLInputElement).blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user