Optimize campaign store use

pull/46/head
HardiReady 2018-10-08 10:53:22 +02:00
parent c9fce51ef6
commit bb69907447
2 changed files with 10 additions and 20 deletions

View File

@ -24,13 +24,14 @@ export class CampaignService {
}
getAllCampaignsWithWars() {
this.http.get(this.config.apiWarPath)
return this.http.get(this.config.apiWarPath)
.map(res => res.json())
.do((ranks) => {
this.campaignStore.dispatch({type: LOAD, data: ranks});
}).subscribe(_ => {
});
return this.campaigns$;
.do((ranks) => this.campaignStore.dispatch({type: LOAD, data: ranks}))
}
getCampaign(id: string) {
return this.http.get(this.config.apiCampaignPath + '/' + id)
.map(res => res.json());
}
submitCampaign(campaign: Campaign) {
@ -63,13 +64,6 @@ export class CampaignService {
deleteCampaign(campaign: Campaign) {
return this.http.delete(this.config.apiCampaignPath + '/' + campaign._id)
.do(res => {
this.campaignStore.dispatch({type: REMOVE, data: campaign});
});
}
getCampaign(id: string) {
return this.http.get(this.config.apiCampaignPath + '/' + id)
.map(res => res.json());
.do(res => this.campaignStore.dispatch({type: REMOVE, data: campaign}));
}
}

View File

@ -12,7 +12,7 @@ import {SettingsService} from '../services/settings.service';
})
export class StatisticComponent implements OnInit {
selectedCampaign: Campaign;
selectedCampaign: Campaign = {};
campaigns: Campaign[] = [];
@ -27,7 +27,7 @@ export class StatisticComponent implements OnInit {
}
ngOnInit() {
this.campaignService.getAllCampaignsWithWars().subscribe((campaigns) => {
this.campaignService.getAllCampaignsWithWars().filter(c => c.length !== 0).subscribe((campaigns) => {
this.campaigns = campaigns;
this.selectedCampaign = this.resolveCampaignFromUrl();
this.switchCampaign(this.selectedCampaign);
@ -35,10 +35,6 @@ export class StatisticComponent implements OnInit {
}
resolveCampaignFromUrl() {
if (this.campaigns.length === 0) {
return {};
}
const url = this.router.url;
const idFetchPattern = /right:.*\/(.*)\)$/;