import { Control, Controller, FieldPath, FieldValues, RefCallBack, UseControllerProps, } from 'react-hook-form'; import { FileInputContentBlank, FileInputContentFile } from './FileInput'; import { useElectron } from '@/hooks/electron'; export function InnerSystemFileInput({ label, value, onChange, directory, ref, }: { label: string; value: string | null; onChange: (...event: any[]) => void; directory: boolean; ref: RefCallBack; }) { const electron = useElectron(); const handleClick = async () => { if (!electron.isElectron) return; const open = await electron.api.openDialog({ properties: ['openDirectory'], }); if (open.canceled) { onChange(null); return; } onChange(open.filePaths[0]); }; return (
{value !== null ? FileInputContentFile({ directory, importedFileName: value, onClearPicker: () => onChange(null), }) : FileInputContentBlank({ isDragging: false, label, directory })}
); } export function SystemFileInput({ control, rules, name, label, directory = false, }: { rules: UseControllerProps>['rules']; control: Control; /** * Use a translation key! **/ label: string; name: FieldPath; directory?: boolean; disabled?: boolean; }) { return ( ( )} /> ); }