-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update Angular configuration for development environment and f…
…ix chat component
- Loading branch information
1 parent
882108a
commit bcf0828
Showing
4 changed files
with
59 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 42 additions & 25 deletions
67
EdVenture-FrontEnd/src/app/components/dashboard/chat/chat.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,67 @@ | ||
import { CommonModule } from '@angular/common' | ||
import { Component, OnInit } from '@angular/core' | ||
import { RouterLink } from '@angular/router' | ||
import { CookieService } from 'ngx-cookie-service' | ||
import { HttpClient, HttpClientModule } from '@angular/common/http' | ||
import { FormsModule } from '@angular/forms' // import the FormsModule | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { RouterLink } from '@angular/router'; | ||
import { CookieService } from 'ngx-cookie-service'; | ||
import { HttpClient, HttpClientModule } from '@angular/common/http'; | ||
import { environment } from '../../../../environments/environment'; | ||
import { FormsModule } from '@angular/forms'; // import the FormsModule | ||
|
||
@Component({ | ||
selector: 'app-chat', | ||
standalone: true, | ||
imports: [RouterLink, CommonModule, HttpClientModule, FormsModule], | ||
templateUrl: './chat.component.html', | ||
styleUrl: './chat.component.css' | ||
styleUrls: ['./chat.component.css'] // Corrected to styleUrls | ||
}) | ||
export class ChatComponent implements OnInit { | ||
loggedInUsername: string = '' | ||
messages: any[] = [] // Initialize the messages array with type any[] | ||
loggedInUsername: string = ''; | ||
messages: any[] = []; // Initialize the messages array with type any[] | ||
|
||
constructor (private http: HttpClient, private cookieService: CookieService) {} | ||
content: string = ''; // Add a content property to the ChatComponent class | ||
|
||
ngOnInit () { | ||
this.loggedInUsername = this.cookieService.get('loggedInUsername') | ||
constructor(private http: HttpClient, private cookieService: CookieService) {} | ||
|
||
ngOnInit() { | ||
if (!environment.enableHttpRequests) return; // Check if HTTP requests are enabled | ||
|
||
this.loggedInUsername = this.cookieService.get('loggedInUsername'); | ||
|
||
setInterval(() => { | ||
this.http | ||
.get('http://edventure.azurewebsites.net/api/v1/group/getmsgs', { | ||
.get<{ msgs: any[] }>('http://localhost:3000/api/v1/group/getmsgs', { | ||
params: { loggedInUsername: this.loggedInUsername } | ||
}) | ||
.subscribe((response: any) => { | ||
this.messages = response.msgs // Changed from response.messages to response.msgs | ||
}) | ||
}, 1000) | ||
.subscribe({ | ||
next: (response) => { | ||
this.messages = response.msgs; // Changed from response.messages to response.msgs | ||
}, | ||
error: (error) => { | ||
console.error('Error fetching messages:', error); | ||
} | ||
}); | ||
}, 1000); | ||
} | ||
|
||
content: string = '' // Add a content property to the ChatComponent class | ||
sendMessage() { | ||
if (!environment.enableHttpRequests) return; // Check if HTTP requests are enabled | ||
|
||
sendMessage () { | ||
const body = { | ||
groupName: 'Group2', | ||
from: 'itsUser1', | ||
from: this.loggedInUsername, // Use the logged-in username dynamically | ||
content: this.content | ||
} // create the body of the request | ||
}; // create the body of the request | ||
|
||
this.http | ||
.post('http://edventure.azurewebsites.net/api/v1/group/msgGroup', body) | ||
.subscribe((response: any) => {}) | ||
.post('http://localhost:3000/api/v1/group/msgGroup', body) | ||
.subscribe({ | ||
next: (response) => { | ||
console.log('Message sent:', response); | ||
}, | ||
error: (error) => { | ||
console.error('Error sending message:', error); | ||
} | ||
}); | ||
|
||
this.content = '' // clear the input field | ||
this.content = ''; // clear the input field | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
EdVenture-FrontEnd/src/environments/environment.development.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const environment = { | ||
production: false, | ||
enableHttpRequests: true, // Enable HTTP requests for development | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const environment = { | ||
production: true, | ||
enableHttpRequests: false, // Disable HTTP requests for production | ||
}; | ||
|