um-react/src/components/SelectFile.tsx

53 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Box, Text } from '@chakra-ui/react';
2023-05-07 22:29:37 +00:00
import { UnlockIcon } from '@chakra-ui/icons';
2023-06-03 13:13:37 +00:00
import { useAppDispatch } from '~/hooks';
import { addNewFile, processFile } from '~/features/file-listing/fileListingSlice';
import { nanoid } from 'nanoid';
import { FileInput } from './FileInput';
2023-05-07 19:11:16 +00:00
export function SelectFile() {
const dispatch = useAppDispatch();
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
for (const file of 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 }));
}
};
2023-05-07 19:11:16 +00:00
return (
<FileInput multiple onReceiveFiles={handleFileReceived}>
2023-05-07 22:29:37 +00:00
<Box pb={3}>
<UnlockIcon boxSize={8} />
</Box>
<Text as="div" textAlign="center">
<Text as="span" color="teal.400">
2023-05-07 22:29:37 +00:00
</Text>
2023-05-07 22:29:37 +00:00
<Text fontSize="sm" opacity="50%">
2023-05-07 22:29:37 +00:00
</Text>
</Text>
</FileInput>
2023-05-07 19:11:16 +00:00
);
}