diff --git a/.gitignore b/.gitignore index 30bc9bc..5bb3acb 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ /.idea/modules.xml /.idea/Proof_Of_Concept.iml /.idea/vcs.xml +.idea/sonarlint/* diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 03c5104..f72177f 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -7,7 +7,7 @@ const routes: Routes = [ ]; @NgModule({ - imports: [RouterModule.forRoot(routes)], + imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})], exports: [RouterModule] }) export class AppRoutingModule { } diff --git a/frontend/src/app/pages/service-client/service-client.component.ts b/frontend/src/app/pages/service-client/service-client.component.ts index 4b9cb7d..2a76b1c 100644 --- a/frontend/src/app/pages/service-client/service-client.component.ts +++ b/frontend/src/app/pages/service-client/service-client.component.ts @@ -1,7 +1,7 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, Validators } from '@angular/forms'; -import { Router } from '@angular/router'; -import { Observable } from 'rxjs'; +import { NavigationEnd, Router } from '@angular/router'; +import { Observable, Subscription } from 'rxjs'; import { Message } from 'src/app/interface/message'; import { MessageRequest } from 'src/app/payload/messageRequest'; import { MessageService } from 'src/app/service/message.service'; @@ -11,13 +11,23 @@ import { MessageService } from 'src/app/service/message.service'; templateUrl: './service-client.component.html', styleUrls: ['./service-client.component.scss'] }) -export class ServiceClientComponent { +export class ServiceClientComponent implements OnInit, OnDestroy{ constructor(private router: Router, private messageService: MessageService, - private fb: FormBuilder) { } + private fb: FormBuilder) { + + } + + ngOnInit(): void { + //throw new Error('Method not implemented.'); + this.router.routeReuseStrategy.shouldReuseRoute = function () { + return false; + }; + } // This is subscribed in DOM with async public posts$: Observable = this.messageService.getMessages(); + public sendingMessage$!: Subscription; public form = this.fb.group({ content: ['', @@ -28,10 +38,23 @@ export class ServiceClientComponent { ] }); + + public submit(): void{ const request = this.form.value as MessageRequest; request.author = "Utilisateur"; - //const createpostRequest = this.form.value as Message; - this.messageService.sendMessage(request).subscribe(); + this.sendingMessage$ = this.messageService.sendMessage(request).subscribe({ + next: () =>{ + //this.router.navigate(["ServiceClientComponent"]); + //this.sendingMessage$ = this.messageService.getMessages().subscribe(); + window.location.reload(); + } + }); } + + ngOnDestroy(): void { + if(this.sendingMessage$) this.sendingMessage$.unsubscribe(); + } + + }