Skip to content

Commit a47be77

Browse files
reniowoodcopybara-github
authored andcommitted
ADK changes
PiperOrigin-RevId: 861541983
1 parent 8d7d724 commit a47be77

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

src/app/components/message-feedback/message-feedback.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="message-feedback-container">
22
<div class="feedback-buttons">
33
<button mat-icon-button [matTooltip]="i18n.goodResponseTooltip" (click)="sendFeedback('up')">
4-
@if (selectedFeedback() === 'up') {
4+
@if (feedbackDirection() === 'up') {
55
<mat-icon>thumb_up_filled</mat-icon>
66
} @else {
77
<mat-icon>thumb_up</mat-icon>
88
}
99
</button>
1010
<button mat-icon-button [matTooltip]="i18n.badResponseTooltip" (click)="sendFeedback('down')">
11-
@if (selectedFeedback() === 'down') {
11+
@if (feedbackDirection() === 'down') {
1212
<mat-icon>thumb_down_filled</mat-icon>
1313
} @else {
1414
<mat-icon>thumb_down</mat-icon>

src/app/components/message-feedback/message-feedback.component.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
*/
1717

1818
import {CommonModule} from '@angular/common';
19-
import {Component, computed, inject, input, signal} from '@angular/core';
19+
import {Component, computed, effect, inject, input, resource, signal} from '@angular/core';
20+
import {rxResource, toSignal} from '@angular/core/rxjs-interop';
2021
import {FormControl, ReactiveFormsModule} from '@angular/forms';
2122
import {MatButtonModule} from '@angular/material/button';
2223
import {MatFormFieldModule} from '@angular/material/form-field';
@@ -50,23 +51,35 @@ export class MessageFeedbackComponent {
5051
protected readonly i18n = inject(MessageFeedbackMessagesInjectionToken);
5152
private readonly feedbackService = inject(FEEDBACK_SERVICE);
5253

53-
readonly isDetailedFeedbackVisible = signal(false);
54-
readonly selectedFeedback =
54+
private readonly existingFeedback = rxResource({
55+
params: () => ({
56+
sessionName: this.sessionName(),
57+
eventId: this.eventId(),
58+
}),
59+
stream: ({params}) =>
60+
this.feedbackService.getFeedback(params.sessionName, params.eventId)
61+
});
62+
private readonly selectedFeedbackDirection =
5563
signal<Feedback['direction']|undefined>(undefined);
64+
65+
readonly feedbackDirection = computed(
66+
() => this.selectedFeedbackDirection() ??
67+
this.existingFeedback.value()?.direction);
68+
readonly isDetailedFeedbackVisible = signal(false);
5669
readonly feedbackPlaceholder = computed(() => {
57-
return this.selectedFeedback() === 'up' ?
70+
return this.feedbackDirection() === 'up' ?
5871
this.i18n.feedbackCommentPlaceholderUp :
5972
this.i18n.feedbackCommentPlaceholderDown;
6073
});
6174
readonly comment = new FormControl('');
6275

6376
sendFeedback(direction: Feedback['direction']) {
6477
this.isDetailedFeedbackVisible.set(true);
65-
this.selectedFeedback.set(direction);
78+
this.selectedFeedbackDirection.set(direction);
6679
}
6780

6881
onDetailedFeedbackSubmitted() {
69-
const direction = this.selectedFeedback();
82+
const direction = this.feedbackDirection();
7083
if (!direction) return;
7184

7285
this.feedbackService.sendFeedback(this.sessionName(), this.eventId(), {
@@ -77,7 +90,7 @@ export class MessageFeedbackComponent {
7790
}
7891

7992
onDetailedFeedbackCancelled() {
80-
this.selectedFeedback.set(undefined);
93+
this.selectedFeedbackDirection.set(undefined);
8194
this.resetDetailedFeedback();
8295
}
8396

src/app/core/services/feedback.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import {Injectable} from '@angular/core';
1919

2020
import {Feedback, FeedbackService as FeedbackServiceInterface} from './interfaces/feedback';
21+
import {Observable, of} from 'rxjs';
2122

2223
@Injectable({providedIn: 'root'})
2324
export class FeedbackService implements FeedbackServiceInterface {
@@ -26,4 +27,9 @@ export class FeedbackService implements FeedbackServiceInterface {
2627
eventId: string,
2728
feedback: Partial<Feedback>,
2829
): void {}
30+
31+
getFeedback(sessionId: string, eventId: string):
32+
Observable<Feedback|undefined> {
33+
return of(undefined);
34+
}
2935
}

src/app/core/services/interfaces/feedback.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import {InjectionToken} from '@angular/core';
19+
import {Observable} from 'rxjs';
1920

2021
/**
2122
* Feedback metadata.
@@ -36,6 +37,8 @@ export declare abstract class FeedbackService {
3637
eventId: string,
3738
feedback: Partial<Feedback>,
3839
): void;
40+
abstract getFeedback(sessionId: string, eventId: string):
41+
Observable<Feedback|undefined>;
3942
}
4043

4144
/**

src/app/core/services/testing/mock-feedback.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18+
import {of} from 'rxjs';
19+
1820
import {FeedbackService} from '../interfaces/feedback';
1921

2022
/**
2123
* Mock feedback service for testing.
2224
*/
2325
export class MockFeedbackService implements Partial<FeedbackService> {
24-
sendFeedback = jasmine.createSpy('sendFeedback');
26+
sendFeedback =
27+
jasmine.createSpy('sendFeedback').and.returnValue(of(undefined));
28+
getFeedback = jasmine.createSpy('getFeedback').and.returnValue(of(undefined));
2529
}

0 commit comments

Comments
 (0)