Skip to content

Commit 4d25437

Browse files
committed
Fix merge conflicts
2 parents a4ea983 + 4d3cb1c commit 4d25437

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

frontend/src/app/questions/question-dialog.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<label for="questionTopics">Topics</label>
3030

3131
<p-multiSelect
32+
#topicSelector
3233
required="true"
3334
class="w-12"
3435
[style]="{ width: '100%' }"
@@ -43,8 +44,13 @@
4344
</ng-template>
4445

4546
<ng-template pTemplate="footer" class="w-12 p-fluid">
46-
@if (isNoResultsFound) {
47-
<p-button type="button" label="Add as New Topic" icon="pi pi-plus" (click)="addNewTopic()" />
47+
@if (hasNoResultsFound) {
48+
<p-button
49+
class="w-12 p-fluid"
50+
type="button"
51+
label="Add as New Topic"
52+
icon="pi pi-plus"
53+
(click)="addNewTopic()" />
4854
}
4955
</ng-template>
5056
</p-multiSelect>

frontend/src/app/questions/question-dialog.component.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
1+
import { Component, EventEmitter, Input, Output, OnInit, ViewChild } from '@angular/core';
22
import { Question, QuestionBody, SingleQuestionResponse } from './question.model';
33
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
44
import { DialogModule } from 'primeng/dialog';
5-
import { MultiSelectModule } from 'primeng/multiselect';
5+
import { MultiSelect, MultiSelectModule } from 'primeng/multiselect';
66
import { DropdownModule } from 'primeng/dropdown';
77
import { ButtonModule } from 'primeng/button';
88
import { ConfirmationService, MessageService } from 'primeng/api';
@@ -29,6 +29,7 @@ import { DifficultyLevels } from './difficulty-levels.enum';
2929
styleUrl: './question-dialog.component.css',
3030
})
3131
export class QuestionDialogComponent implements OnInit {
32+
@ViewChild('topicSelector') topicSelector!: MultiSelect;
3233
@Input() question!: Question;
3334
@Input() isDialogVisible = false;
3435
@Output() dialogClose = new EventEmitter<void>();
@@ -38,7 +39,6 @@ export class QuestionDialogComponent implements OnInit {
3839
@Output() successfulRequest = new EventEmitter<string>();
3940

4041
questionFormGroup!: FormGroup;
41-
4242
submitted = false;
4343

4444
topicSearchValue = '';
@@ -49,10 +49,10 @@ export class QuestionDialogComponent implements OnInit {
4949

5050
difficulties!: Difficulty[];
5151

52-
isNoResultsFound = false;
53-
5452
filteredTopics: Topic[] = [];
5553

54+
hasNoResultsFound = false;
55+
5656
constructor(private questionService: QuestionService) {}
5757

5858
ngOnInit(): void {
@@ -63,6 +63,10 @@ export class QuestionDialogComponent implements OnInit {
6363
this.initTopics();
6464
}
6565

66+
get topicControl(): FormControl {
67+
return this.questionFormGroup.controls['topics'] as FormControl;
68+
}
69+
6670
get isTitleInvalid(): boolean {
6771
const titleControl = this.questionFormGroup.controls['title'];
6872
return titleControl.dirty && titleControl.invalid;
@@ -202,28 +206,29 @@ export class QuestionDialogComponent implements OnInit {
202206

203207
onFilterTopics(event: { filter: string }) {
204208
this.topicSearchValue = event.filter;
205-
206-
this.filteredTopics = this.topics.filter(topic =>
209+
this.hasNoResultsFound = !this.topics.some(topic =>
207210
topic.label.toLowerCase().includes(this.topicSearchValue.toLowerCase()),
208211
);
209-
210-
this.isNoResultsFound = this.filteredTopics.length == 0;
211212
}
212213

213214
addNewTopic() {
215+
const newTopic = this.topicSearchValue;
214216
const newValue: Topic = {
215-
label: this.topicSearchValue,
216-
value: this.topicSearchValue,
217+
label: newTopic,
218+
value: newTopic,
217219
};
218220

219-
const topicExists = this.topics.some(
220-
topic =>
221-
topic.label.toLowerCase() === newValue.label.toLowerCase() ||
222-
topic.value.toLowerCase() === newValue.value.toLowerCase(),
223-
);
221+
const topicExists = this.topics.map(t => t.label).some(l => l.toLowerCase() === newTopic.toLowerCase());
224222

225-
if (!topicExists) {
226-
this.topics = [...this.topics, newValue];
223+
if (topicExists) {
224+
return;
227225
}
226+
227+
this.topics.push(newValue);
228+
229+
// Immediately add the new topic, and clear the search filter
230+
this.topicControl.setValue(this.topicControl.value?.concat([newTopic]) ?? [newTopic]);
231+
this.topicSelector.resetFilter();
232+
this.hasNoResultsFound = false;
228233
}
229234
}

frontend/src/app/questions/questions.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { QuestionService } from '../../_services/question.service';
1717
import { forkJoin } from 'rxjs';
1818
import { HttpErrorResponse } from '@angular/common/http';
1919
import { QuestionDialogComponent } from './question-dialog.component';
20+
import { Column } from './column.model';
2021

2122
@Component({
2223
selector: 'app-questions',
@@ -47,6 +48,8 @@ export class QuestionsComponent implements OnInit {
4748

4849
questions: Question[] = [];
4950

51+
cols: Column[] = [];
52+
5053
question!: Question;
5154

5255
selectedQuestions!: Question[] | null;

0 commit comments

Comments
 (0)