import React, { useRef } from 'react'; import { ActionIcon, Tooltip, Group } from '@mantine/core'; import { IconPlus, IconTrash, IconGitPullRequest, IconGitCommit, IconUpload, IconEdit, } from '@tabler/icons-react'; import { useModalContext } from '../../contexts/ModalContext'; import { useWorkspace } from '../../hooks/useWorkspace'; import { useFileOperations } from '../../hooks/useFileOperations'; interface FileActionsProps { handlePullChanges: () => Promise; selectedFile: string | null; loadFileList: () => Promise; } const FileActions: React.FC = ({ handlePullChanges, selectedFile, loadFileList, }) => { const { currentWorkspace } = useWorkspace(); const { setNewFileModalVisible, setDeleteFileModalVisible, setCommitMessageModalVisible, setRenameFileModalVisible, } = useModalContext(); const { handleUpload } = useFileOperations(); // Hidden file input for upload const fileInputRef = useRef(null); const handleCreateFile = (): void => setNewFileModalVisible(true); const handleDeleteFile = (): void => setDeleteFileModalVisible(true); const handleRenameFile = (): void => setRenameFileModalVisible(true); const handleCommitAndPush = (): void => setCommitMessageModalVisible(true); const handleUploadClick = (): void => { fileInputRef.current?.click(); }; const handleFileInputChange = ( event: React.ChangeEvent ): void => { const files = event.target.files; if (files && files.length > 0) { const uploadFiles = async () => { try { const success = await handleUpload(files); if (success) { await loadFileList(); } } catch (error) { console.error('Error uploading files:', error); } }; void uploadFiles(); // Reset the input so the same file can be selected again event.target.value = ''; } }; return ( { handlePullChanges().catch((error) => { console.error('Error pulling changes:', error); }); }} disabled={!currentWorkspace?.gitEnabled} aria-label="Pull changes from remote" data-testid="pull-changes-button" > {/* Hidden file input */} ); }; export default FileActions;