🐛 fix fetch of old params

This commit is contained in:
Baptiste Lemoine 2020-01-23 14:23:07 +01:00
parent 7e4e80f1ed
commit 01bddc842d
7 changed files with 41 additions and 27 deletions

View File

@ -1,7 +1,9 @@
import {Component, Inject} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {Router} from '@angular/router';
import {NavigationStart, Router} from '@angular/router';
import {DOCUMENT} from "@angular/common";
import {filter} from "rxjs/operators";
import {ConfigService} from "./services/config.service";
@Component({
selector: 'app-root',
@ -22,6 +24,7 @@ export class AppComponent {
step: string;
constructor(private translate: TranslateService,
private config : ConfigService,
@Inject(DOCUMENT) private document,
private route: Router) {
this.translate.setDefaultLang(this.currentLang);
@ -31,20 +34,16 @@ export class AppComponent {
detectCurrentTabOnRouteChange() {
this.route.events.subscribe((event: any) => {
this.scrollGoToTop();
console.log('event', event)
if (event.url) {
const tab = event.url.split('/');
if (tab && tab[2]) {
this.step = tab[2];
} else {
this.step = 'home';
}
}
});
this.route.events.pipe(filter(event => event instanceof NavigationStart)).subscribe((event:NavigationStart) => {
this.scrollGoToTop();
this.updateCurrentTab(event);
// only if there is a poll ID
this.config.fetchPollFromRoute(event);
})
}
switchLanguage(language: string) {
@ -76,4 +75,15 @@ export class AppComponent {
scrollGoToTop() {
this.document.documentElement.scrollTop = 0;
}
updateCurrentTab(event){
if (event.url) {
const tab = event.url.split('/');
if (tab && tab[2]) {
this.step = tab[2];
} else {
this.step = 'home';
}
}
}
}

View File

@ -41,6 +41,7 @@ export class PollConfig {
creationDate = new Date();
expirationDate = ''; // expiracy date
pollId = null; // id of the current poll when created. data given by the backend api
pollSlug = null; // id of the current poll when created. data given by the backend api
currentPoll; // current poll selected with createPoll or getPoll of ConfigService
passwordAccess = 0;
password = '';

View File

@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core';
import {BaseComponent} from "../base-page/base.component";
import {ConfigService} from "../../services/config.service";
import {mockComments} from "../../config/mocks/mock-comments";
import {ActivatedRoute, Router, RouterEvent} from "@angular/router";
import {ActivatedRoute, Router} from "@angular/router";
@Component({
selector: 'framadate-poll-display',
@ -17,13 +17,12 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
private router: Router,
public activeRoute: ActivatedRoute) {
super(config);
router.events.subscribe((val: RouterEvent) => {
// see also
console.log(this.activeRoute);
if (val.url && !this.config.loading) {
this.activeRoute.paramMap.subscribe(params => {
console.log('params', params)
this.config.pollId = params.get('poll');
this.config.pollSlug = params.get('pollSlug');
if (!this.config.loading) {
this.fetchPoll();
}
});
}
@ -41,11 +40,12 @@ export class PollDisplayComponent extends BaseComponent implements OnInit {
if (id) {
this.config.loading = true;
this.config.pollId = id;
// store it in the poll property here
this.config.getPollById(id).subscribe(
(res: any) => {
console.log('res', res)
this.config.pollId = id;
this.config.currentPoll = res;
this.config.loading = false;
}, (e) => {

View File

@ -3,7 +3,7 @@
{{comment.pseudo}}
</span >, le
<span class="date padding-btm-x1" >
{{comment.date.date | date:'medium'}}
{{comment.date.date }}
</span >
<blockquote >
<p class="text" >

View File

@ -244,7 +244,10 @@ export class ConfigService extends PollConfig {
return this.http
.get(`${this.baseHref}/poll/${id}`,
this.makeHeaders({body: password}))
}
fetchPollFromRoute(event) {
console.log('time to fetch poll', event)
}
/**
@ -273,8 +276,6 @@ export class ConfigService extends PollConfig {
createPoll() {
this.loading = true;
this.createPollFromConfig(this.getPollConfig())
}
/**
@ -335,6 +336,7 @@ export class ConfigService extends PollConfig {
votes: this.convertChoicesAnsweredToSend(this.currentPoll.choices),
}
}
console.log('voteStack', voteStack)
this.http.post(
`${this.baseHref}/poll/${this.currentPoll.id}/vote`,
voteStack,
@ -383,8 +385,9 @@ export class ConfigService extends PollConfig {
text: this.myComment,
}
}
console.log('comment', comment)
this.http.post(
`${this.baseHref}/poll/${this.currentPoll.id}/comment`,
`${this.baseHref}/poll/${this.pollId}/comment`,
comment,
this.makeHeaders())
.subscribe((res: any) => {

View File

@ -70,12 +70,12 @@
Page démo
</a >
<a
[routerLink]="'/vote/poll/id/3'"
[routerLink]="['vote/poll/id/',3]"
i18n >
Sondage dessins animés
</a >
<a
[routerLink]="'/vote/poll/id/4'"
[routerLink]="['vote/poll/id/',4]"
i18n >
Sondage 4
</a >

View File

@ -5,7 +5,7 @@ let baseURL = "http://localhost:8000/";
const baseURLProd = "https://framadate.org/";
const baseURLDemo = "https://framadate-api.cipherbliss.com/";
const apiVersion = 1;
const testOnDemo = 1;
const testOnDemo = 0;
if (testOnDemo) {
baseURL = baseURLDemo;
}