mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
⚡ update vote list after vote creation
This commit is contained in:
parent
123a0b1c80
commit
06cf447529
@ -237,4 +237,4 @@ export const mockPoll3 = {
|
||||
}
|
||||
],
|
||||
"comments": mockComments
|
||||
}
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ import {ActivatedRoute} from "@angular/router";
|
||||
})
|
||||
export class PollDisplayComponent extends BaseComponent implements OnInit {
|
||||
|
||||
private pollConfigFetched = mockPoll3;
|
||||
private pollConfigFetched;
|
||||
private comments = mockComments;
|
||||
|
||||
constructor(public config: ConfigService,
|
||||
@ -21,6 +21,8 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.pollConfigFetched = this.config.currentPoll;
|
||||
|
||||
// fetch poll with its ID or slug.
|
||||
const id = this.activeRoute.snapshot.params.poll;
|
||||
if (id) {
|
||||
@ -28,7 +30,7 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
|
||||
// store it in the poll property here
|
||||
this.config.getPollById(id).subscribe(
|
||||
(res: any) => {
|
||||
this.pollConfigFetched = res;
|
||||
this.config.currentPoll = res;
|
||||
}, (e) => {
|
||||
// handle need for a password
|
||||
this.config.handleError(e)
|
||||
|
@ -4,6 +4,7 @@ import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||
import {environment} from "../../environments/environment";
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {Router} from "@angular/router";
|
||||
import {mockPoll3} from "../config/mocks/mock-poll3";
|
||||
|
||||
/**
|
||||
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
|
||||
@ -13,6 +14,7 @@ import {Router} from "@angular/router";
|
||||
})
|
||||
export class ConfigService extends PollConfig {
|
||||
|
||||
currentPoll: any = mockPoll3;
|
||||
loading: boolean = false;
|
||||
baseHref: any = environment.baseApiHref;
|
||||
|
||||
@ -307,8 +309,7 @@ export class ConfigService extends PollConfig {
|
||||
.subscribe((res: any) => {
|
||||
|
||||
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
|
||||
alert("succès!");
|
||||
this.myPolls = res;
|
||||
this.currentPoll = res;
|
||||
}, (e) => {
|
||||
this.handleError(e)
|
||||
}
|
||||
@ -327,7 +328,7 @@ export class ConfigService extends PollConfig {
|
||||
this.makeHeaders())
|
||||
.subscribe((res: any) => {
|
||||
this.messageService.add({severity: 'success', summary: 'Vote mis à jour'});
|
||||
this.myPolls = res;
|
||||
this.currentPoll = res;
|
||||
}, (e) => {
|
||||
this.handleError(e)
|
||||
}
|
||||
@ -340,10 +341,11 @@ export class ConfigService extends PollConfig {
|
||||
* @param comment
|
||||
*/
|
||||
addComment(comment?: any) {
|
||||
if (!comment) {
|
||||
if (!comment && this.myComment) {
|
||||
comment = {
|
||||
pseudo: this.myName,
|
||||
comment: this.myComment,
|
||||
name: this.myName,
|
||||
date: new Date(),
|
||||
text: this.myComment,
|
||||
}
|
||||
}
|
||||
this.http.post(
|
||||
@ -358,8 +360,10 @@ export class ConfigService extends PollConfig {
|
||||
});
|
||||
// empty comment after success
|
||||
this.myComment = '';
|
||||
this.currentPoll.comments.push(comment);
|
||||
}, (e) => {
|
||||
this.handleError(e)
|
||||
this.handleError(e);
|
||||
this.currentPoll.comments.push(comment);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -463,7 +467,7 @@ export class ConfigService extends PollConfig {
|
||||
severity: 'success',
|
||||
summary: 'Sondage mis à jour',
|
||||
});
|
||||
this.myPolls = res;
|
||||
this.currentPoll = res;
|
||||
}, (e) => {
|
||||
this.handleError(e)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user