@@ -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 (
0 commit comments