Ability to open workspace from directory, WorkspaceMeta, and many sync improvements

This commit is contained in:
Gregory Schier
2025-01-08 14:57:13 -08:00
parent 37671a50f2
commit cbc443075a
71 changed files with 1012 additions and 1844 deletions

View File

@@ -1,3 +1,4 @@
import { readDir } from '@tauri-apps/plugin-fs';
import { useState } from 'react';
import { Checkbox } from './core/Checkbox';
import { VStack } from './core/Stacks';
@@ -6,10 +7,16 @@ import { SelectFile } from './SelectFile';
export interface SyncToFilesystemSettingProps {
onChange: (args: { value: string | null; enabled: boolean }) => void;
value: string | null;
allowNonEmptyDirectory?: boolean;
}
export function SyncToFilesystemSetting({ onChange, value }: SyncToFilesystemSettingProps) {
export function SyncToFilesystemSetting({
onChange,
value,
allowNonEmptyDirectory,
}: SyncToFilesystemSettingProps) {
const [useSyncDir, setUseSyncDir] = useState<boolean>(!!value);
const [error, setError] = useState<string | null>(null);
return (
<VStack space={1.5} className="w-full">
@@ -26,19 +33,28 @@ export function SyncToFilesystemSetting({ onChange, value }: SyncToFilesystemSet
}}
title="Sync to a filesystem directory"
/>
{error && <div className="text-danger">{error}</div>}
{useSyncDir && (
<>
<SelectFile
directory
size="xs"
noun="Directory"
filePath={value}
onChange={({ filePath }) => {
if (filePath == null) setUseSyncDir(false);
onChange({ value: filePath, enabled: useSyncDir });
}}
/>
</>
<SelectFile
directory
size="xs"
noun="Directory"
filePath={value}
onChange={async ({ filePath }) => {
setError(null);
if (filePath == null) {
setUseSyncDir(false);
} else {
const files = await readDir(filePath);
if (files.length > 0 && !allowNonEmptyDirectory) {
setError('Directory must be empty');
return;
}
}
onChange({ value: filePath, enabled: useSyncDir });
}}
/>
)}
</VStack>
);