Skip to content

Commit

Permalink
use structuredCloning
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 3, 2024
1 parent 0d737bd commit 80f5938
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions apps/fxc-front/src/app/components/ui/main-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,18 +628,18 @@ export class TrackItems extends connect(store)(LitElement) {
(this.renderRoot.querySelector('#track') as HTMLInputElement)?.click();
}

private async handleUpload(e: Event): Promise<void> {
private async handleUpload(e: Event & { target: HTMLInputElement }): Promise<void> {
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 = '';
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions libs/optimizer/src/lib/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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({
Expand Down

0 comments on commit 80f5938

Please sign in to comment.