2023-05-08 15:06:52 +00:00
|
|
|
|
import React, { useId } from 'react';
|
2023-05-07 22:29:37 +00:00
|
|
|
|
|
|
|
|
|
import { Box, Text } from '@chakra-ui/react';
|
|
|
|
|
import { UnlockIcon } from '@chakra-ui/icons';
|
2023-05-08 15:06:52 +00:00
|
|
|
|
import { useAppDispatch } from './hooks';
|
|
|
|
|
import { addNewFile } from './features/file-listing/fileListingSlice';
|
|
|
|
|
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-07 19:11:16 +00:00
|
|
|
|
const id = useId();
|
|
|
|
|
|
2023-05-08 15:06:52 +00:00
|
|
|
|
const handleFileSelection = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
if (e.target.files) {
|
|
|
|
|
for (const file of e.target.files) {
|
|
|
|
|
const blobURI = URL.createObjectURL(file);
|
|
|
|
|
const fileName = file.name;
|
|
|
|
|
dispatch(
|
|
|
|
|
addNewFile({
|
|
|
|
|
id: nanoid(),
|
|
|
|
|
blobURI,
|
|
|
|
|
fileName,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.target.value = '';
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-07 19:11:16 +00:00
|
|
|
|
return (
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Box
|
|
|
|
|
as="label"
|
|
|
|
|
htmlFor={id}
|
|
|
|
|
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',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box pb={3}>
|
|
|
|
|
<UnlockIcon boxSize={8} />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box textAlign="center">
|
|
|
|
|
{/* 将文件拖到此处,或 */}
|
|
|
|
|
<Text as="span" color="teal.400">
|
|
|
|
|
点我选择
|
|
|
|
|
</Text>
|
|
|
|
|
需要解密的文件
|
2023-05-08 15:06:52 +00:00
|
|
|
|
<input id={id} type="file" hidden multiple onChange={handleFileSelection} />
|
2023-05-07 22:29:37 +00:00
|
|
|
|
<Text fontSize="sm" opacity="50%">
|
|
|
|
|
仅在浏览器内对文件进行解锁,无需消耗流量
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2023-05-07 19:11:16 +00:00
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|