diff --git a/apps/fxc-front/src/app/components/ui/main-menu.ts b/apps/fxc-front/src/app/components/ui/main-menu.ts index 823fb9cd..66591ad7 100644 --- a/apps/fxc-front/src/app/components/ui/main-menu.ts +++ b/apps/fxc-front/src/app/components/ui/main-menu.ts @@ -628,18 +628,18 @@ export class TrackItems extends connect(store)(LitElement) { (this.renderRoot.querySelector('#track') as HTMLInputElement)?.click(); } - private async handleUpload(e: Event): Promise { + private async handleUpload(e: Event & { target: HTMLInputElement }): Promise { if (e.target) { - const el = e.target as HTMLInputElement; - if (el.files?.length) { + const input = e.target; + if (input.files?.length) { const files: File[] = []; - for (let i = 0; i < el.files.length; i++) { - files.push(el.files[i]); + for (let i = 0; i < input.files.length; i++) { + files.push(input.files[i]); } const ids = await uploadTracks(files); pushCurrentState(); addUrlParamValues(ParamNames.groupId, ids); - el.value = ''; + input.value = ''; } } } diff --git a/libs/optimizer/src/lib/optimizer.ts b/libs/optimizer/src/lib/optimizer.ts index 2bffe644..28dcebb9 100644 --- a/libs/optimizer/src/lib/optimizer.ts +++ b/libs/optimizer/src/lib/optimizer.ts @@ -99,8 +99,7 @@ export function* getOptimizer( }; } const originalTrack = request.track; - const solverTrack = appendPointsIfNeeded(originalTrack, MIN_IGC_XC_SCORE_POINTS); - const flight = toIgcFile(solverTrack); + const flight = toIgcFile(appendPointsIfNeeded(originalTrack, MIN_IGC_XC_SCORE_POINTS)); const solverScoringRules = scoringRules.get(ruleName); const options = toSolverOptions(request); const solutionIterator = solver(flight, solverScoringRules || {}, options); @@ -120,13 +119,13 @@ export function* getOptimizer( * The points are close enough to the last point to not affect the score. */ function appendPointsIfNeeded(track: ScoringTrack, minValidLength: number) { + track = structuredClone(track); + if (track.points.length >= minValidLength) { return track; } // console.debug(`The track is too short, appending (${MIN_IGC_XC_SCORE_POINTS - track.points.length}) points`); - - track = JSON.parse(JSON.stringify(track)); while (track.points.length < minValidLength) { const lastPoint = track.points.at(-1)!; track.points.push({