import React, { useId } from 'react'; import { Box, Text } from '@chakra-ui/react'; import { UnlockIcon } from '@chakra-ui/icons'; import { useAppDispatch } from './hooks'; import { addNewFile, processFile } from './features/file-listing/fileListingSlice'; import { nanoid } from 'nanoid'; export function SelectFile() { const dispatch = useAppDispatch(); const id = useId(); const handleFileSelection = (e: React.ChangeEvent) => { if (e.target.files) { for (const file of e.target.files) { const blobURI = URL.createObjectURL(file); const fileName = file.name; const fileId = 'file://' + nanoid(); // 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)); } } e.target.value = ''; }; return ( {/* 将文件拖到此处,或 */} 点我选择 需要解密的文件 仅在浏览器内对文件进行解锁,无需消耗流量 ); }