Skip to content

Commit 76b3396

Browse files
committed
Feed backend parse response into new frontend parse-results component
Instead of handling it in the input component.
1 parent 9774833 commit 76b3396

5 files changed

Lines changed: 25 additions & 36 deletions

File tree

frontend/src/app/annotate/annotation-input/annotation-input.component.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import { ProblemDetailsComponent } from "./problem-details/problem-details.compo
1717
import { map, Subject } from "rxjs";
1818
import { ActivatedRoute, Router, RouterLinkWithHref } from "@angular/router";
1919
import { ProblemService } from "@/services/problem.service";
20-
import { ParseResponse, ParseService } from "@/services/parse.service";
20+
import { ParseService } from "@/services/parse.service";
2121
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
2222
import { ToastService } from "@/services/toast.service";
2323
import { AuthService } from "@/services/auth.service";
2424
import { IconButtonComponent } from "@/shared/icon-button/icon-button.component";
25-
import { Tree } from "@/tree";
2625

2726
export type ParseInputForm = FormGroup<{
2827
id: FormControl<number | null>;
@@ -74,8 +73,6 @@ export class AnnotationInputComponent implements OnInit {
7473

7574
public submit$ = new Subject<void>();
7675

77-
public ccgTrees: Tree<string>[] = [];
78-
7976
public faCopy = faCopy;
8077
public faCheck = faCheck;
8178
public faTree = faTree;
@@ -123,27 +120,14 @@ export class AnnotationInputComponent implements OnInit {
123120
});
124121
this.router.navigate(["/", "annotate", response.id]);
125122
});
126-
127-
// Subscription needed to ensure a request is actually made.
128-
// TODO: replace this with actual parse results.
129-
this.parseService.parse$
130-
.pipe(takeUntilDestroyed(this.destroyRef))
131-
.subscribe((response) => {
132-
console.log("Parse response:", response);
133-
});
134-
}
135-
136-
onParse(response: ParseResponse) {
137-
console.log("Parse response:", response);
138-
this.ccgTrees = response!.data.ccg_trees.map((tree: any) => new Tree(tree));
139123
}
140124

141125
public startParse(): void {
142126
if (!this.form || this.form.invalid) {
143127
return;
144128
}
145129
const input = this.form.getRawValue();
146-
this.parseService.startParse(input, (r) => this.onParse(r));
130+
this.parseService.submit$.next(input);
147131
}
148132

149133
public saveProblem(): void {

frontend/src/app/annotate/annotation-menu/annotation-menu.component.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
<span i18n>CCG / LLF</span>
1010
</button>
1111
<ng-template ngbNavContent>
12-
@for(tree of ccgTrees; track $index) {
13-
<la-parse-svg [tree]="tree"></la-parse-svg>
14-
}
12+
<la-annotation-parse-results />
1513
</ng-template>
1614
</li>
1715
<li [ngbNavItem]="2">
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Component, Input } from "@angular/core";
1+
import { Component } from "@angular/core";
22
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
33
import { NgbNavModule } from "@ng-bootstrap/ng-bootstrap";
44
import {
55
faSquarePollHorizontal,
66
faTree,
77
faPenNib,
88
} from "@fortawesome/free-solid-svg-icons";
9+
import { AnnotationParseResultsComponent } from "../annotation-parse-results/annotation-parse-results.component";
910
import { AnnotationTableauComponent } from "../annotation-tableau/annotation-tableau.component";
1011
import { AnnotationCommentsComponent } from "../annotation-comments/annotation-comments.component";
11-
import { ParseSVG } from "../parse-tree/parse-svg.component";
1212

1313
@Component({
1414
selector: "la-annotation-menu",
1515
standalone: true,
1616
imports: [
1717
NgbNavModule,
1818
FontAwesomeModule,
19+
AnnotationParseResultsComponent,
1920
AnnotationTableauComponent,
2021
AnnotationCommentsComponent,
21-
ParseSVG
2222
],
2323
templateUrl: "./annotation-menu.component.html",
2424
styleUrl: "./annotation-menu.component.scss",
@@ -29,7 +29,4 @@ export class AnnotationMenuComponent {
2929
public faSquarePollHorizontal = faSquarePollHorizontal;
3030
public faTree = faTree;
3131
public faPenNib = faPenNib;
32-
33-
@Input()
34-
public ccgTrees: any[] = [];
3532
}

frontend/src/app/annotate/annotation-parse-results/annotation-parse-results.component.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { Component } from "@angular/core";
1+
import { Component, DestroyRef, inject, OnInit } from "@angular/core";
2+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
23
import { mockResult } from "./mockParseResult";
4+
import { ParseResponse, ParseService } from "@/services/parse.service";
35
import { ParseTreeTableComponent } from "./parse-tree-table/parse-tree-table.component";
46
import { NgbAccordionModule } from "@ng-bootstrap/ng-bootstrap";
57

@@ -11,6 +13,19 @@ import { NgbAccordionModule } from "@ng-bootstrap/ng-bootstrap";
1113
templateUrl: "./annotation-parse-results.component.html",
1214
styleUrl: "./annotation-parse-results.component.scss",
1315
})
14-
export class AnnotationParseResultsComponent {
15-
public readonly parseResults = mockResult;
16+
export class AnnotationParseResultsComponent implements OnInit {
17+
private destroyRef = inject(DestroyRef);
18+
private parseService = inject(ParseService);
19+
20+
public parseResults = mockResult;
21+
22+
ngOnInit(): void {
23+
// Subscription needed to ensure a request is actually made.
24+
this.parseService.parse$
25+
.pipe(takeUntilDestroyed(this.destroyRef))
26+
.subscribe((response) => {
27+
console.log("Parse response:", response);
28+
this.parseResults = response.data.ccg_trees;
29+
});
30+
}
1631
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient } from '@angular/common/http';
22
import { inject, Injectable } from '@angular/core';
3-
import { Subject, switchMap, catchError, of, first } from 'rxjs';
3+
import { Subject, switchMap, catchError, of } from 'rxjs';
44
import { ParseInput } from '@/annotate/annotation-input/annotation-input.component';
55

66
export type ParseResponse = any;
@@ -23,9 +23,4 @@ export class ParseService {
2323
)
2424
)
2525
);
26-
27-
public startParse(input: ParseInput, handler: (response: ParseResponse) => void) {
28-
this.parse$.pipe(first()).subscribe(handler);
29-
this.submit$.next(input);
30-
}
3126
}

0 commit comments

Comments
 (0)