2023-06-11 15:21:10 +00:00
|
|
|
|
import { Box, Text } from '@chakra-ui/react';
|
2023-05-07 22:29:37 +00:00
|
|
|
|
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-06-11 15:21:10 +00:00
|
|
|
|
import { FileInput } from './FileInput';
|
2023-05-07 19:11:16 +00:00
|
|
|
|
|
|
|
|
|
export function SelectFile() {
|
2023-05-08 15:06:52 +00:00
|
|
|
|
const dispatch = useAppDispatch();
|
2023-06-11 15:21:10 +00:00
|
|
|
|
const handleFileReceived = (files: File[]) => {
|
|
|
|
|
console.debug(
|
|
|
|
|
'react-dropzone/onDropAccepted(%o, %o)',
|
|
|
|
|
files.length,
|
|
|
|
|
files.map((x) => x.name)
|
|
|
|
|
);
|
2023-05-07 19:11:16 +00:00
|
|
|
|
|
2023-06-11 15:21:10 +00:00
|
|
|
|
for (const file of files) {
|
|
|
|
|
const blobURI = URL.createObjectURL(file);
|
|
|
|
|
const fileName = file.name;
|
|
|
|
|
const fileId = 'file://' + nanoid();
|
2023-05-21 15:36:21 +00:00
|
|
|
|
|
2023-06-11 15:21:10 +00:00
|
|
|
|
// FIXME: this should be a single action/thunk that first adds the item, then updates it.
|
|
|
|
|
dispatch(
|
|
|
|
|
addNewFile({
|
|
|
|
|
id: fileId,
|
|
|
|
|
blobURI,
|
|
|
|
|
fileName,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
dispatch(processFile({ fileId }));
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-05-08 15:06:52 +00:00
|
|
|
|
|
2023-05-07 19:11:16 +00:00
|
|
|
|
return (
|
2023-06-11 15:21:10 +00:00
|
|
|
|
<FileInput multiple onReceiveFiles={handleFileReceived}>
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Box pb={3}>
|
|
|
|
|
<UnlockIcon boxSize={8} />
|
|
|
|
|
</Box>
|
2023-06-11 15:21:10 +00:00
|
|
|
|
<Text as="div" textAlign="center">
|
2023-06-10 16:54:24 +00:00
|
|
|
|
拖放或
|
2023-06-11 15:21:10 +00:00
|
|
|
|
<Text as="span" color="teal.400">
|
2023-05-07 22:29:37 +00:00
|
|
|
|
点我选择
|
2023-06-11 15:21:10 +00:00
|
|
|
|
</Text>
|
2023-05-07 22:29:37 +00:00
|
|
|
|
需要解密的文件
|
|
|
|
|
<Text fontSize="sm" opacity="50%">
|
2023-06-10 16:54:24 +00:00
|
|
|
|
在浏览器内对文件进行解锁,零上传
|
2023-05-07 22:29:37 +00:00
|
|
|
|
</Text>
|
2023-06-10 16:54:24 +00:00
|
|
|
|
</Text>
|
2023-06-11 15:21:10 +00:00
|
|
|
|
</FileInput>
|
2023-05-07 19:11:16 +00:00
|
|
|
|
);
|
|
|
|
|
}
|