mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
added comment form drop zone
This commit is contained in:
parent
63b9781977
commit
62d4e03206
8 changed files with 142 additions and 93 deletions
|
@ -1,19 +1,18 @@
|
|||
import {
|
||||
useCallback, useEffect, useRef, useState
|
||||
} from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
export const useCloseOnEscape = (onRequestClose: () => void, ignore_inputs = false) => {
|
||||
const onEscape = useCallback(
|
||||
(event) => {
|
||||
event => {
|
||||
if (event.key !== 'Escape') return;
|
||||
if (
|
||||
ignore_inputs
|
||||
&& (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA')
|
||||
) return;
|
||||
ignore_inputs &&
|
||||
(event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA')
|
||||
)
|
||||
return;
|
||||
|
||||
onRequestClose();
|
||||
},
|
||||
[ignore_inputs, onRequestClose],
|
||||
[ignore_inputs, onRequestClose]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -34,3 +33,24 @@ export const useDelayedReady = (setReady: (val: boolean) => void, delay: number
|
|||
};
|
||||
}, [delay, setReady]);
|
||||
};
|
||||
|
||||
/**
|
||||
* useDropZone returns onDrop handler to upload files
|
||||
* @param onUpload -- upload callback
|
||||
* @param allowedTypes -- list of allowed types
|
||||
*/
|
||||
export const useDropZone = (onUpload: (file: File[]) => void, allowedTypes?: string[]) => {
|
||||
return useCallback(
|
||||
event => {
|
||||
event.preventDefault();
|
||||
const files: File[] = Array.from((event.dataTransfer?.files as File[]) || []).filter(
|
||||
(file: File) => file?.type && (!allowedTypes || allowedTypes.includes(file.type))
|
||||
);
|
||||
|
||||
if (!files || !files.length) return;
|
||||
|
||||
onUpload(files);
|
||||
},
|
||||
[onUpload]
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue