From ebef6fc40664aa2bdfcd0b7b4d0488dcd6f349a8 Mon Sep 17 00:00:00 2001 From: FTCHD Date: Fri, 31 Jan 2025 16:27:52 +0200 Subject: [PATCH] fields facelift for create/edit drawers --- src/components/RemoteCreateDrawer.tsx | 286 +++++++++++++++----------- src/components/RemoteEditDrawer.tsx | 101 +++++---- 2 files changed, 211 insertions(+), 176 deletions(-) diff --git a/src/components/RemoteCreateDrawer.tsx b/src/components/RemoteCreateDrawer.tsx index 792298b..407c4dc 100644 --- a/src/components/RemoteCreateDrawer.tsx +++ b/src/components/RemoteCreateDrawer.tsx @@ -1,7 +1,16 @@ import { Drawer, DrawerBody, DrawerFooter, DrawerHeader } from '@nextui-org/drawer' -import { Button, DrawerContent } from '@nextui-org/react' +import { + Autocomplete, + AutocompleteItem, + Button, + Checkbox, + DrawerContent, + Input, + Select, + SelectItem, +} from '@nextui-org/react' import { message } from '@tauri-apps/plugin-dialog' -import { ChevronDown, ChevronUp } from 'lucide-react' +import { ChevronDown, ChevronUp, RefreshCcwIcon } from 'lucide-react' import { useEffect, useMemo, useState } from 'react' import { createRemote } from '../../lib/rclone/api' import { getBackends } from '../../lib/rclone/api' @@ -27,7 +36,9 @@ export default function RemoteCreateDrawer({ const handleTypeChange = (e: React.ChangeEvent) => { const newType = e.target.value - setConfig({ type: newType }) + + // preserve name when resetting type + setConfig((prev) => ({ name: prev.name, type: newType })) } const renderField = (option: BackendOption) => { @@ -45,92 +56,117 @@ export default function RemoteCreateDrawer({ switch (option.Type) { case 'bool': return ( -
- +
+ + setConfig({ ...config, [option.Name]: checked }) + } + > + {option.Name} + {option.Help.includes('\n') && ( -

+

{option.Help.split('\n').slice(1).join('\n')}

)}
+ // + // setConfig({ ...config, [option.Name]: e.target.checked }) + // } + // autoComplete="off" + // autoCapitalize="off" + // autoCorrect="off" + // spellCheck={false} + // /> ) case 'string': { if (option.Examples && option.Examples.length > 0) { return ( -
- - - {option.Help.includes('\n') && ( -

- {option.Help.split('\n').slice(1).join('\n')} -

+ { + // console.log(value) + setConfig({ ...config, [option.Name]: value }) + }} + > + {(item) => ( + + {item.Help || item.Value} + )} -
+ ) } return ( -
- - - setConfig({ ...config, [option.Name]: e.target.value }) - } - required={option.Required} - autoComplete="off" - autoCapitalize="off" - autoCorrect="off" - spellCheck={false} - /> - {option.Help.includes('\n') && ( -

- {option.Help.split('\n').slice(1).join('\n')} -

- )} -
+ { + // console.log(value) + setConfig({ ...config, [option.Name]: value }) + }} + /> ) + // if (option.Examples && option.Examples.length > 0) { + // return ( + // + // ) + // } + // return ( + // + // setConfig({ ...config, [option.Name]: e.target.value }) + // } + // /> + // ) } default: return null @@ -208,55 +244,59 @@ export default function RemoteCreateDrawer({ {(close) => ( <> - Create Remote + + Create Remote + + -
-
- - - setConfig({ ...config, name: e.target.value }) - } - required={true} - autoComplete="off" - autoCapitalize="off" - autoCorrect="off" - spellCheck={false} - /> -
+ + setConfig({ ...config, name: value })} + isRequired={true} + autoComplete="off" + autoCapitalize="off" + autoCorrect="off" + spellCheck={false} + /> -
- - -
+ {/* Normal Fields */} {currentBackendFields @@ -279,7 +319,7 @@ export default function RemoteCreateDrawer({ More Options {showMoreOptions && ( -
+
{currentBackendFields .filter((opt) => opt.Advanced) .map(renderField)} diff --git a/src/components/RemoteEditDrawer.tsx b/src/components/RemoteEditDrawer.tsx index 4314c26..09dc5f7 100644 --- a/src/components/RemoteEditDrawer.tsx +++ b/src/components/RemoteEditDrawer.tsx @@ -1,6 +1,13 @@ import { Checkbox } from '@nextui-org/checkbox' import { Drawer, DrawerBody, DrawerContent, DrawerFooter, DrawerHeader } from '@nextui-org/drawer' -import { Button, Input } from '@nextui-org/react' +import { + Autocomplete, + AutocompleteItem, + Button, + Input, + Select, + SelectItem, +} from '@nextui-org/react' import { message } from '@tauri-apps/plugin-dialog' import { ChevronDown, ChevronUp } from 'lucide-react' import { useEffect, useState } from 'react' @@ -59,7 +66,7 @@ export default function RemoteEditDrawer({ switch (option.Type) { case 'bool': return ( -
+
{option.Help.includes('\n') && ( -

+

{option.Help.split('\n').slice(1).join('\n')}

)} @@ -77,34 +84,26 @@ export default function RemoteEditDrawer({ case 'string': { if (option.Examples && option.Examples.length > 0) { return ( -
- - - {option.Help.includes('\n') && ( -

- {option.Help.split('\n').slice(1).join('\n')} -

+ + {(item) => ( + + {item.Help || item.Value} + )} -
+ ) } return ( -
- - -
+ {/* Basic Options */} {currentBackend?.Options.filter((opt) => !opt.Advanced).map( @@ -268,7 +263,7 @@ export default function RemoteEditDrawer({ color="primary" type="submit" form="remote-form" - isLoading={isSaving} + isDisabled={isSaving} data-focus-visible="false" > {isSaving ? 'Saving...' : 'Save Changes'}