2023-05-21 15:36:21 +00:00
|
|
|
|
import { useDropzone } from 'react-dropzone';
|
2023-05-07 22:29:37 +00:00
|
|
|
|
import { Box, Text } from '@chakra-ui/react';
|
|
|
|
|
import { UnlockIcon } from '@chakra-ui/icons';
|
2023-05-21 15:36:21 +00:00
|
|
|
|
|
2023-06-03 13:13:37 +00:00
|
|
|
|
import { useAppDispatch } from '~/hooks';
|
|
|
|
|
import { addNewFile, processFile } from '~/features/file-listing/fileListingSlice';
|
2023-05-08 15:06:52 +00:00
|
|
|
|
import { nanoid } from 'nanoid';
|
2023-05-07 19:11:16 +00:00
|
|
|
|
|
|
|
|
|
export function SelectFile() {
|
2023-05-08 15:06:52 +00:00
|
|
|
|
const dispatch = useAppDispatch();
|
2023-05-21 15:36:21 +00:00
|
|
|
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
|
|
|
multiple: true,
|
|
|
|
|
onDropAccepted(files, _event) {
|
|
|
|
|
console.debug(
|
|
|
|
|
'react-dropzone/onDropAccepted(%o, %o)',
|
|
|
|
|
files.length,
|
|
|
|
|
files.map((x) => x.name)
|
|
|
|
|
);
|
2023-05-07 19:11:16 +00:00
|
|
|
|
|
2023-05-21 15:36:21 +00:00
|
|
|
|
for (const file of files) {
|
2023-05-08 15:06:52 +00:00
|
|
|
|
const blobURI = URL.createObjectURL(file);
|
|
|
|
|
const fileName = file.name;
|
2023-05-08 16:36:10 +00:00
|
|
|
|
const fileId = 'file://' + nanoid();
|
2023-05-21 15:36:21 +00:00
|
|
|
|
|
2023-05-08 16:36:10 +00:00
|
|
|
|
// FIXME: this should be a single action/thunk that first adds the item, then updates it.
|
2023-05-08 15:06:52 +00:00
|
|
|
|
dispatch(
|
|
|
|
|
addNewFile({
|
2023-05-08 16:36:10 +00:00
|
|
|
|
id: fileId,
|
2023-05-08 15:06:52 +00:00
|
|
|
|
blobURI,
|
|
|
|
|
fileName,
|
|
|
|
|
})
|
|
|
|
|
);
|
2023-05-09 00:23:35 +00:00
|
|
|
|
dispatch(processFile({ fileId }));
|
2023-05-08 15:06:52 +00:00
|
|
|
|
}
|
2023-05-21 15:36:21 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
2023-05-08 15:06:52 +00:00
|
|
|
|
|
2023-05-07 19:11:16 +00:00
|
|
|
|
return (
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Box
|
2023-05-21 15:36:21 +00:00
|
|
|
|
{...getRootProps()}
|
2023-05-07 22:29:37 +00:00
|
|
|
|
w="100%"
|
|
|
|
|
maxW={480}
|
|
|
|
|
borderWidth="1px"
|
|
|
|
|
borderRadius="lg"
|
|
|
|
|
transitionDuration="0.5s"
|
|
|
|
|
p="6"
|
|
|
|
|
cursor="pointer"
|
|
|
|
|
display="flex"
|
|
|
|
|
flexDir="column"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
_hover={{
|
|
|
|
|
borderColor: 'gray.400',
|
|
|
|
|
bg: 'gray.50',
|
|
|
|
|
}}
|
2023-05-21 15:36:21 +00:00
|
|
|
|
{...(isDragActive && {
|
|
|
|
|
bg: 'blue.50',
|
|
|
|
|
borderColor: 'blue.700',
|
|
|
|
|
})}
|
2023-05-07 22:29:37 +00:00
|
|
|
|
>
|
2023-05-21 15:36:21 +00:00
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
|
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Box pb={3}>
|
|
|
|
|
<UnlockIcon boxSize={8} />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box textAlign="center">
|
2023-05-21 15:36:21 +00:00
|
|
|
|
将文件拖到此处,或
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Text as="span" color="teal.400">
|
|
|
|
|
点我选择
|
|
|
|
|
</Text>
|
|
|
|
|
需要解密的文件
|
|
|
|
|
<Text fontSize="sm" opacity="50%">
|
|
|
|
|
仅在浏览器内对文件进行解锁,无需消耗流量
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2023-05-07 19:11:16 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|