mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 17:39:12 +01:00
Ability to open workspace from directory, WorkspaceMeta, and many sync improvements
This commit is contained in:
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user