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

View File

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