import { readDir } from "@tauri-apps/plugin-fs"; import { Banner, VStack } from "@yaakapp-internal/ui"; import { useState } from "react"; import { openWorkspaceFromSyncDir } from "../commands/openWorkspaceFromSyncDir"; import { Button } from "./core/Button"; import { Checkbox } from "./core/Checkbox"; import { SettingRowBoolean, SettingRowDirectory } from "./core/SettingRow"; import { SelectFile } from "./SelectFile"; export interface SyncToFilesystemSettingProps { layout?: "form" | "settings"; onChange: (args: { filePath: string | null; initGit?: boolean }) => void; onCreateNewWorkspace: () => void; value: { filePath: string | null; initGit?: boolean }; } export function SyncToFilesystemSetting({ layout = "form", onChange, onCreateNewWorkspace, value, }: SyncToFilesystemSettingProps) { const [syncDir, setSyncDir] = useState(null); const handleFilePathChange = async (filePath: string | null) => { if (filePath != null) { const files = await readDir(filePath); if (files.length > 0) { setSyncDir(filePath); return; } } setSyncDir(null); onChange({ ...value, filePath }); }; if (layout === "settings") { return ( {syncDir && (

Directory is not empty. Do you want to open it instead?

)} {value.filePath && typeof value.initGit === "boolean" && ( onChange({ ...value, initGit })} /> )}
); } return ( {syncDir && (

Directory is not empty. Do you want to open it instead?

)} handleFilePathChange(filePath)} /> {value.filePath && typeof value.initGit === "boolean" && ( onChange({ ...value, initGit })} title="Initialize Git Repo" /> )}
); }