Commit 091a09cc authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

no more duplicates

parent ec28d490
......@@ -22,12 +22,12 @@
<div class="container py-3" *ngIf="amis!=null">
<div *ngFor="let ami of amis; let i=index">
<h4>{{ami.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="refuser(ami)">
<div class="btn btn-primary" (click)="refuser(ami, i)">
<h6>Effacer</h6>
</div>
<!-- <div class="btn btn-primary" (click)="">
<div class="btn btn-primary" (click)="challenge(ami)">
<h6>Défier</h6>
</div> -->
</div>
</div>
</div>
</div>
......@@ -37,10 +37,10 @@
<div class="container py-3" *ngIf="requests!=null">
<div *ngFor="let req of requests; let i=index">
<h4>{{req.pseudo}}</h4>
<div class="btn btn-primary" id="ami" (click)="accepter(req)">
<div class="btn btn-primary" (click)="accepter(req, i)">
<h6>Accepter</h6>
</div>
<div class="btn btn-primary" id="ami" (click)="refuser(req)">
<div class="btn btn-primary" (click)="refuser(req,i)">
<h6>Refuser</h6>
</div>
</div>
......
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { FormControl } from '@angular/forms';
import { ChatService } from '../chat.service';
@Component({
selector: 'app-friends',
......@@ -24,7 +25,7 @@ export class FriendsMenuComponent implements OnInit {
uid;
temp;
constructor(private httpClient: HttpClient) { }
constructor(private httpClient: HttpClient, private chatService: ChatService) { }
displayPlayers(play){
this.currentAmi = play;
......@@ -36,9 +37,12 @@ export class FriendsMenuComponent implements OnInit {
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/newami', { id_joueur2: this.currentAmi.id_joueur}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
(response: any) => {
if(response.res){
this.amis.push(this.requests[this.currentAmi]);
}
}
)
}
......@@ -56,16 +60,16 @@ export class FriendsMenuComponent implements OnInit {
isFriend(){
if(this.resultat.res.length > 0){
for(let i = 0; i < this.resultat.res.length; i++){
if(this.resultat.res[i].accept === 1){
if(this.resultat.res[i].accept == 1){
this.amis.push(this.resultat.res[i])
} else if (this.resultat.res[i].id_joueur1 != this.uid){
} else {
this.requests.push(this.resultat.res[i])
}
}
}
}
accepter(idAmi){
accepter(idAmi, i){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
......@@ -74,12 +78,15 @@ export class FriendsMenuComponent implements OnInit {
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/yayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
(response: any) => {
if(response.res){
this.amis.push(this.requests[i]);
}
}
)
}
refuser(idAmi){
refuser(idAmi, i){
if(idAmi.id_joueur1 == this.uid){
this.temp = idAmi.id_joueur2
} else {
......@@ -87,12 +94,31 @@ export class FriendsMenuComponent implements OnInit {
}
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: this.temp}, { headers: headers, withCredentials: true}).subscribe(
this.httpClient.post('http://localhost:3000/nayami', { id_joueur2: this.temp }, { headers: headers, withCredentials: true}).subscribe(
(response: any) => {
if(response.res){
this.requests.splice(i, 1);
}
}
)
}
challenge(user){
if(this.chatService.attaquer(user)){
this.addPartie(user);
console.log("sending challenge");
}
}
addPartie(user){
const headers = new HttpHeaders()
.set('Content-Type', 'application/json');
this.httpClient.post('http://localhost:3000/addpartie', {pseudo: user}, { headers: headers, withCredentials: true}).subscribe(
(response) => console.log(response),
(error) => console.log(error)
)
}
liste(){
this.httpClient.get("http://localhost:3000/alljoueurs", { responseType: 'json', withCredentials:true}).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment