Skip to content

Commit

Permalink
chore: Update Angular configuration for development environment and f…
Browse files Browse the repository at this point in the history
…ix chat component
  • Loading branch information
HarshitShukla-dev committed Jul 15, 2024
1 parent 882108a commit bcf0828
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
8 changes: 7 additions & 1 deletion EdVenture-FrontEnd/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
"sourceMap": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down
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
}
}
}
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
};

5 changes: 5 additions & 0 deletions EdVenture-FrontEnd/src/environments/environment.ts
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
};

0 comments on commit bcf0828

Please sign in to comment.