@@ -9,9 +9,10 @@ import { polyfillPromiseWithResolvers } from "./polyfilsResolver";
99
1010import "core-js/full/promise/with-resolvers.js" ;
1111
12- import { parseItems , parseTranscript } from "../utils/parseUtils" ;
12+ import { parseItems , parseTranscript , ParsedText , flattenParsedText } from "../utils/parseUtils" ;
1313import WelcomeLayout from "@/components/OnboardingPanels/WelcomePanel" ;
1414import CreateWithTranscriptPanel from "@/components/OnboardingPanels/CreateWithTranscriptPanel" ;
15+
1516polyfillPromiseWithResolvers ( ) ;
1617
1718pdfjs . GlobalWorkerOptions . workerSrc = `//unpkg.com/pdfjs-dist@${ pdfjs . version } /legacy/build/pdf.worker.min.mjs` ;
@@ -44,24 +45,26 @@ const OnboardingPage = ({
4445 > ( `/api/degree/degrees` ) ;
4546
4647 // TRANSCRIPT PARSING
47- const total = useRef < any > ( { } ) ;
48+ const total = useRef < Record < number , ParsedText [ ] > > ( { } ) ;
4849 const addText = ( items : any [ ] , index : number ) => {
49- const allText : any = parseItems ( items ) ;
50- let textResult = [ ] ;
51- for ( let col in allText ) {
52- let poses = Object . keys ( allText [ col ] ) . reverse ( ) ;
53- for ( let i in poses ) {
54- textResult . push ( allText [ col ] [ poses [ i ] ] . join ( "" ) . toLowerCase ( ) ) ;
55- }
56- total . current [ index ] = textResult ;
57- }
50+ const parsed = parseItems ( items ) ;
51+ total . current [ index ] = total . current [ index ] ?? [ ] ;
52+ total . current [ index ] . push ( parsed ) ;
5853
5954 // If all pages have been read, begin to parse text from transcript
6055 if ( Object . keys ( total . current ) . length === numPages ) {
61- let all : any = [ ] ;
62- for ( let key in Object . keys ( total . current ) . sort ( ) ) {
63- all = all . concat ( total . current [ key ] ) ;
64- }
56+ let all : string [ ] = [ ] ;
57+ const sortedPageIndexes = Object . keys ( total . current )
58+ . map ( ( key ) => Number ( key ) )
59+ . sort ( ( a , b ) => a - b ) ;
60+
61+ sortedPageIndexes . forEach ( ( pageIndex ) => {
62+ const pageEntries = total . current [ pageIndex ] ;
63+ if ( ! pageEntries ) return ;
64+ pageEntries . forEach ( ( pageText ) => {
65+ all = all . concat ( flattenParsedText ( pageText ) ) ;
66+ } ) ;
67+ } ) ;
6568
6669 const {
6770 scrapedCourses,
0 commit comments