2025-03-30 21:47:18 -03:00
|
|
|
import { core } from '@tauri-apps/api';
|
|
|
|
|
2025-03-30 16:42:51 -03:00
|
|
|
import { useState } from 'react';
|
2025-03-30 21:47:18 -03:00
|
|
|
|
2025-03-30 16:42:51 -03:00
|
|
|
|
|
|
|
interface FileOperationsProps {
|
|
|
|
currentPath: string;
|
|
|
|
onRefresh: () => void;
|
|
|
|
}
|
|
|
|
|
2025-03-30 19:28:28 -03:00
|
|
|
export function FileOperations({ currentPath, onRefresh }: FileOperationsProps) {
|
2025-03-30 16:42:51 -03:00
|
|
|
const [uploadProgress, setUploadProgress] = useState(0);
|
|
|
|
|
|
|
|
const handleUpload = async () => {
|
|
|
|
try {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Upload failed:', error);
|
|
|
|
alert('Upload failed!');
|
|
|
|
} finally {
|
|
|
|
setUploadProgress(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const createFolder = async () => {
|
|
|
|
const folderName = prompt('Enter folder name:');
|
|
|
|
if (folderName) {
|
|
|
|
try {
|
2025-03-30 21:47:18 -03:00
|
|
|
await core.invoke('create_folder', {
|
2025-03-30 16:42:51 -03:00
|
|
|
path: currentPath,
|
|
|
|
name: folderName
|
|
|
|
});
|
|
|
|
onRefresh();
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error creating folder:', error);
|
|
|
|
alert('Failed to create folder');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="p-4 border-t border-gray-300 space-y-3">
|
|
|
|
<h3 className="text-lg font-semibold">File Operations</h3>
|
|
|
|
<div className="flex space-x-2">
|
|
|
|
<button
|
|
|
|
onClick={handleUpload}
|
|
|
|
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
|
|
|
|
>
|
|
|
|
Upload
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={createFolder}
|
|
|
|
className="bg-green-500 text-white px-4 py-2 rounded hover:bg-green-600"
|
|
|
|
>
|
|
|
|
New Folder
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{uploadProgress > 0 && (
|
|
|
|
<div className="w-full bg-gray-200 rounded-full h-2.5">
|
|
|
|
<div
|
|
|
|
className="bg-blue-600 h-2.5 rounded-full"
|
|
|
|
style={{ width: `${uploadProgress}%` }}
|
|
|
|
></div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2025-03-30 19:28:28 -03:00
|
|
|
}
|