Skip to content

Commit 7188e7f

Browse files
Outfactor general utility function
1 parent f43bd3f commit 7188e7f

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

frontend/src/app/services/problem.service.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ParseInput } from "@/annotate/annotation-input/annotation-input.component";
2+
import extractBaseParam from "@/shared/extractBaseParam";
23
import { ProblemResponse, SaveProblemResponse, Dataset, EntailmentLabel } from "@/types";
34
import { HttpClient, HttpParams } from "@angular/common/http";
45
import { Injectable, inject } from "@angular/core";
@@ -35,20 +36,13 @@ export class ProblemService {
3536
if (!problemId) {
3637
return of(null);
3738
}
38-
const baseParam = this.extractBaseParam(queryParams);
39+
const baseParam = extractBaseParam(queryParams);
3940

4041
return problemId === "new" ? this.newProblem$(baseParam) : this.existingProblem$(problemId, queryParams);
4142
}),
4243
shareReplay(1)
4344
);
4445

45-
private extractBaseParam(queryParams: ParamMap): number | null {
46-
const baseStr = queryParams.get("base");
47-
if (!baseStr) {
48-
return null;
49-
}
50-
return parseInt(baseStr, 10);
51-
}
5246

5347
public problem$ = this.problemResponse$.pipe(
5448
map(response => response?.problem ?? null),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ParamMap } from "@angular/router";
2+
3+
/**
4+
* Extracts the base parameter from query parameters and returns it as a number.
5+
* @param queryParams - The query parameters map to extract the base value from.
6+
* @returns The base value as a number, or null if the base parameter is not present.
7+
*/
8+
export default function extractBaseParam(queryParams: ParamMap): number | null {
9+
const baseStr = queryParams.get("base");
10+
if (!baseStr) {
11+
return null;
12+
}
13+
return parseInt(baseStr, 10);
14+
}

0 commit comments

Comments
 (0)