import { readDir } from '@tauri-apps/plugin-fs'; import { useState } from 'react'; import { openWorkspaceFromSyncDir } from '../commands/openWorkspaceFromSyncDir'; import { Banner } from './core/Banner'; import { Button } from './core/Button'; import { Checkbox } from './core/Checkbox'; import { VStack } from './core/Stacks'; import { SelectFile } from './SelectFile'; export interface SyncToFilesystemSettingProps { onChange: (args: { filePath: string | null; initGit?: boolean }) => void; onCreateNewWorkspace: () => void; value: { filePath: string | null; initGit?: boolean }; forceOpen?: boolean; } export function SyncToFilesystemSetting({ onChange, onCreateNewWorkspace, value, forceOpen, }: SyncToFilesystemSettingProps) { const [isNonEmpty, setIsNonEmpty] = useState(null); return (
Data directory {isNonEmpty ? (

The selected directory must be empty. Did you want to open it instead?

) : !value.filePath ? ( Sync data to a folder for backup and Git integration. ) : null} { if (filePath != null) { const files = await readDir(filePath); if (files.length > 0) { setIsNonEmpty(filePath); return; } } setIsNonEmpty(null); onChange({ ...value, filePath }); }} /> {value.filePath && typeof value.initGit === 'boolean' && ( onChange({ ...value, initGit })} title="Initialize Git Repo" /> )}
); }