Skip to content

Commit 7e85531

Browse files
committed
Draft processing
1 parent 0a93135 commit 7e85531

File tree

2 files changed

+88
-19
lines changed

2 files changed

+88
-19
lines changed

apps/frontend/src/components/Main.tsx

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,63 @@ const Main: React.FC = () => {
1818

1919
const [uploadedFiles, setUploadedFiles] = useState<UploadedFile[]>([]);
2020

21-
const handleProcess = () => {
22-
console.log('Processing with metadata:', metadata);
23-
console.log('Processing with files:', uploadedFiles);
24-
// TODO: Implement actual processing logic
21+
const formatMetadataAsHeader = (meta: Metadata): string => {
22+
return `# docId=${meta.docId}
23+
# docTitle=${meta.docTitle}
24+
# contributor=${meta.contributor}
25+
# corpusRef=${meta.corpusRef}
26+
# docAuthor=${meta.docAuthor}
27+
# seeAlso=${meta.seeAlso}
28+
# description=${meta.description}
29+
`;
30+
};
31+
32+
const handleProcess = async () => {
33+
try {
34+
// Format metadata as header
35+
const header = formatMetadataAsHeader(metadata);
36+
37+
// Read all file contents
38+
const fileContents = await Promise.all(
39+
uploadedFiles.map(async (uploadedFile) => {
40+
const content = await readFileContent(uploadedFile.file);
41+
return content;
42+
})
43+
);
44+
45+
// Concatenate header with all file contents
46+
const fullContent = [header, ...fileContents].join('\n');
47+
48+
// Create and download the file
49+
downloadFile(fullContent, 'output.conllu');
50+
} catch (error) {
51+
console.error('Error processing files:', error);
52+
}
53+
};
54+
55+
const readFileContent = (file: File): Promise<string> => {
56+
return new Promise((resolve, reject) => {
57+
const reader = new FileReader();
58+
reader.onload = (e) => {
59+
resolve(e.target?.result as string);
60+
};
61+
reader.onerror = (e) => {
62+
reject(e);
63+
};
64+
reader.readAsText(file);
65+
});
66+
};
67+
68+
const downloadFile = (content: string, filename: string) => {
69+
const blob = new Blob([content], { type: 'text/plain' });
70+
const url = URL.createObjectURL(blob);
71+
const link = document.createElement('a');
72+
link.href = url;
73+
link.download = filename;
74+
document.body.appendChild(link);
75+
link.click();
76+
document.body.removeChild(link);
77+
URL.revokeObjectURL(url);
2578
};
2679

2780
return (

apps/frontend/src/components/ProcessSection.tsx

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Box, Button, Divider, Typography } from '@mui/material';
22
import type React from 'react';
3-
import type { Metadata, UploadedFile } from './MetadataInput';
3+
import type { UploadedFile } from './FileUpload';
4+
import type { Metadata } from './MetadataInput';
45

56
interface ProcessSectionProps {
67
metadata: Metadata;
@@ -21,20 +22,35 @@ const ProcessSection: React.FC<ProcessSectionProps> = ({
2122
<Divider sx={{ mb: 3 }} />
2223

2324
<Box sx={{ textAlign: 'center', py: 3 }}>
24-
<Button
25-
variant="contained"
26-
size="large"
27-
onClick={onProcess}
28-
disabled={uploadedFiles.length === 0}
29-
sx={{
30-
px: 4,
31-
py: 2,
32-
fontSize: '1.2rem',
33-
minWidth: 200,
34-
}}
35-
>
36-
Process Data
37-
</Button>
25+
<Box sx={{ display: 'flex', gap: 2, justifyContent: 'center', alignItems: 'center' }}>
26+
<Button
27+
variant="contained"
28+
size="large"
29+
onClick={onProcess}
30+
disabled={uploadedFiles.length === 0}
31+
sx={{
32+
px: 4,
33+
py: 2,
34+
fontSize: '1.2rem',
35+
minWidth: 200,
36+
}}
37+
>
38+
Download CoNLL-U
39+
</Button>
40+
<Button
41+
variant="outlined"
42+
size="large"
43+
disabled
44+
sx={{
45+
px: 4,
46+
py: 2,
47+
fontSize: '1.2rem',
48+
minWidth: 200,
49+
}}
50+
>
51+
Download Turtle
52+
</Button>
53+
</Box>
3854
{uploadedFiles.length === 0 && (
3955
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
4056
Upload at least one file to enable processing

0 commit comments

Comments
 (0)