Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricting DragZoneFiled File Upload to a Single File #153

Closed
ivam5 opened this issue Dec 1, 2023 · 0 comments · Fixed by #154
Closed

Restricting DragZoneFiled File Upload to a Single File #153

ivam5 opened this issue Dec 1, 2023 · 0 comments · Fixed by #154
Labels
enhancement New feature or request

Comments

@ivam5
Copy link
Collaborator

ivam5 commented Dec 1, 2023

Basic information

  • Tiller version: 1.7.2
  • Module: upload

Enhancement description

Enable the option to upload a single file, simplifying the upload process for users who only need to upload one file at a time.

Current behaviour

The current behavior allows for the upload of a single file multiple times, but not exclusively a single file.

Wanted behaviour

It should be possible to upload only one file, once.

Possible workarounds

export default function DragZoneField<T extends File>({ name, ...props }: DragZoneFieldProps<T>) {
  const [field, , helpers] = useField(name);
  const fieldValue = React.useRef<string[]>();

  React.useEffect(() => {
    props.hook.onUploadedFileIds([field.value]);
    fieldValue.current = field.value;
  }, [field.value]);

  React.useEffect(() => {
    props.hook.onUpdateCallback((added, deleted) => {
      if (added) {
        helpers.setValue(added);
      } else if (deleted) {
        helpers.setValue(null);
      }
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  return <DragZone hook={props.hook} url={props.url} {...props} />;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant