Skip to content

Commit 27e4391

Browse files
committed
merge
2 parents e6a4c29 + 99a8357 commit 27e4391

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,8 @@
111111
}
112112
}
113113
}
114+
},
115+
"cli": {
116+
"analytics": false
114117
}
115118
}

src/app/chat/chat.component.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2>CIT Chatbot</h2>
66
</div>
77

88
<div class="study-program-dropdown">
9-
<label for="studyProgramSelect" class="dropdown-label">Select Study Program:</label>
9+
<label for="studyProgramSelect" class="dropdown-label">{{ dropdownLabel }}</label>
1010
<ng-select class="select" [items]="studyPrograms" bindLabel="label" bindValue="value"
1111
[formControl]="studyProgramControl" placeholder="Select your study program">
1212
</ng-select>
@@ -45,10 +45,13 @@ <h2>CIT Chatbot</h2>
4545
(keydown)="onKeyDown($event)"
4646
[placeholder]="placeholderText"
4747
rows="1"></textarea>
48-
<button (click)="sendMessage()">
49-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 24 24">
50-
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
51-
</svg>
48+
<button
49+
(click)="sendMessage()"
50+
[disabled]="disableSending"
51+
[ngClass]="{ 'disabled': disableSending }">
52+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 24 24">
53+
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
54+
</svg>
5255
</button>
5356
</div>
5457
</div>

src/app/chat/chat.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ $logo-size: 40px;
110110
&:hover {
111111
background-color: $primary-color;
112112
}
113+
114+
&.disabled {
115+
background-color: $border-color;
116+
color: #aaa;
117+
cursor: not-allowed;
118+
}
113119

114120
svg {
115121
fill: white;

src/app/chat/chat.component.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const MESSAGES = {
2121
If you'd like program-specific advice, please select your study program from the dropdown menu at the top, and I'll provide you with the most relevant information.
2222
`,
2323
errorMessage: `Sorry, but I am currently unable to answer your questions. Please try again at a later time.`,
24-
placeholder: `Type your message here...`
24+
placeholder: `Type your message here...`,
25+
dropdownLabel: `Select Study Program:`
2526
},
2627
de: {
2728
welcomeMessage: `
@@ -32,7 +33,8 @@ export const MESSAGES = {
3233
Wenn Sie studiengangspezifische Ratschläge benötigen, wählen Sie bitte Ihr Studienprogramm aus dem Dropdown-Menü oben, und ich werde Ihnen die relevantesten Informationen bereitstellen.
3334
`,
3435
errorMessage: `Entschuldigung, aber ich kann Ihre Fragen derzeit nicht beantworten. Bitte versuchen Sie es später erneut.`,
35-
placeholder: `Geben Sie hier Ihre Nachricht ein...`
36+
placeholder: `Geben Sie hier Ihre Nachricht ein...`,
37+
dropdownLabel: `Studiengang auswählen:`
3638
}
3739
};
3840

@@ -54,13 +56,15 @@ export class ChatComponent implements OnInit, AfterViewChecked {
5456
placeholderText: string = '';
5557
welcomeMessage: string = '';
5658
errorMessage: string = '';
59+
dropdownLabel: string = '';
5760

5861
// FormControl for the study program dropdown
5962
studyProgramControl = new FormControl('');
6063
studyPrograms = studyPrograms;
6164

6265
language: 'en' | 'de' = 'en'; // Default language is English
6366
private needScrollToBottom: boolean = false;
67+
disableSending: boolean = false;
6468

6569
constructor(private chatbotService: ChatbotService, private route: ActivatedRoute) { }
6670

@@ -84,6 +88,7 @@ export class ChatComponent implements OnInit, AfterViewChecked {
8488
this.welcomeMessage = MESSAGES[this.language].welcomeMessage;
8589
this.errorMessage = MESSAGES[this.language].errorMessage;
8690
this.placeholderText = MESSAGES[this.language].placeholder;
91+
this.dropdownLabel = MESSAGES[this.language].dropdownLabel;
8792
}
8893

8994
onKeyDown(event: KeyboardEvent): void {
@@ -92,7 +97,8 @@ export class ChatComponent implements OnInit, AfterViewChecked {
9297
!event.shiftKey &&
9398
!event.ctrlKey &&
9499
!event.altKey &&
95-
!event.metaKey
100+
!event.metaKey &&
101+
!this.disableSending
96102
) {
97103
event.preventDefault(); // Prevents the default action of adding a newline
98104
this.sendMessage();
@@ -102,6 +108,7 @@ export class ChatComponent implements OnInit, AfterViewChecked {
102108
sendMessage() {
103109
if (this.userMessage.trim()) {
104110
// Add the user's message to the messages array
111+
this.disableSending = true;
105112
this.messages.push({ message: this.userMessage, type: 'user' });
106113
this.userMessage = '';
107114
this.resetTextAreaHeight();
@@ -113,9 +120,10 @@ export class ChatComponent implements OnInit, AfterViewChecked {
113120
const loadingMessage: ChatMessage = { message: '', type: 'loading' };
114121
this.messages.push(loadingMessage);
115122
this.needScrollToBottom = true;
116-
117-
// Prepare the messages to send to the bot, excluding the loading message
118-
const messagesToSend = this.messages.filter(msg => msg.type !== 'loading');
123+
124+
const nonLoadingMessages = this.messages.filter(msg => msg.type !== 'loading');
125+
// Keep only the last 5 messages, if there are 5 or more
126+
const messagesToSend = nonLoadingMessages.slice(-5);
119127

120128
// Call the bot service with the filtered messages
121129
this.chatbotService.getBotResponse(messagesToSend, selectedProgram).subscribe({
@@ -126,6 +134,7 @@ export class ChatComponent implements OnInit, AfterViewChecked {
126134
const formattedResponse = this.formatResponseText(response.answer);
127135
this.messages.push({ message: formattedResponse, type: 'system' });
128136
this.needScrollToBottom = true;
137+
this.disableSending = false;
129138
},
130139
error: (error) => {
131140
console.error('Error fetching response:', error);
@@ -137,6 +146,7 @@ export class ChatComponent implements OnInit, AfterViewChecked {
137146
type: 'system'
138147
});
139148
this.needScrollToBottom = true;
149+
this.disableSending = false;
140150
}
141151
});
142152
}

src/app/services/chatbot.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { HttpClient, HttpHeaders } from '@angular/common/http';
1+
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { ChatMessage } from '../chat/chat.component';
4-
import { Observable, switchMap } from 'rxjs';
4+
import { catchError, Observable, switchMap, throwError } from 'rxjs';
55
import { environment } from '../../environments/environment';
66
import { AuthService } from './auth.service';
77

0 commit comments

Comments
 (0)