Commit cab96c03 authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): show sidebar boosts campaigns && put new endpoints behind feature flags

1 merge request!387WIP: Boost Campaigns (&24)
Pipeline #73556573 running with stages
......@@ -5,6 +5,9 @@ import { Session } from '../../services/session';
import { Storage } from '../../services/storage';
import { Subscription } from 'rxjs';
import { SettingsService } from '../settings/settings.service';
import { FeedsService } from "../../common/services/feeds.service";
import { first } from "rxjs/operators";
import { FeaturesService } from "../../services/features.service";
@Component({
selector: 'm-ads-boost',
......@@ -32,7 +35,13 @@ export class BoostAds implements OnInit, OnDestroy {
ratingSubscription: Subscription;
constructor(public client: Client, public session: Session, private storage: Storage, private settingsService: SettingsService) {
constructor(
public client: Client,
public session: Session,
public feedsService: FeedsService,
private featureService: FeaturesService,
private storage: Storage,
private settingsService: SettingsService) {
}
ngOnInit() {
......@@ -40,6 +49,16 @@ export class BoostAds implements OnInit, OnDestroy {
this.ratingSubscription = this.settingsService.ratingChanged.subscribe((rating) => {
this.onRatingChanged(rating);
});
this.feedsService.feed.subscribe(async boosts => {
if (!boosts.length)
return;
for (const boost of boosts) {
if (boost)
this.boosts.push(await boost.pipe(first()).toPromise());
}
});
this.fetch();
}
......@@ -47,7 +66,7 @@ export class BoostAds implements OnInit, OnDestroy {
this.ratingSubscription.unsubscribe();
}
fetch() {
loadLegacy() {
if (this.storage.get('boost:offset:sidebar'))
this.offset = this.storage.get('boost:offset:sidebar');
this.client.get('api/v1/boost/fetch/' + this.handler, {
......@@ -66,9 +85,29 @@ export class BoostAds implements OnInit, OnDestroy {
});
}
load() {
this.feedsService
.setEndpoint('api/v2/boost/fetch/campaigns/content')
.setParams({
rating: this.rating,
})
.setLimit(this.limit)
.setOffset(0)
.fetch();
}
fetch() {
if (this.featureService.has('boost-campaigns')) {
this.load();
} else {
this.loadLegacy();
}
}
onRatingChanged(rating: number) {
this.rating = rating;
this.storage.destroy('boost:offset:sidebar');
this.boosts = [];
this.offset = '';
this.fetch();
}
......
......@@ -66,13 +66,14 @@ export class NewsfeedBoostRotatorComponent {
public scroll: ScrollService,
public newsfeedService: NewsfeedService,
public settingsService: SettingsService,
private storage: Storage,
public element: ElementRef,
public service: NewsfeedBoostService,
public feedsService: FeedsService,
private cd: ChangeDetectorRef,
private storage: Storage,
protected featuresService: FeaturesService,
public feedsService: FeedsService,
protected clientMetaService: ClientMetaService,
protected featureService: FeaturesService,
@SkipSelf() injector: Injector,
) {
......@@ -112,9 +113,10 @@ export class NewsfeedBoostRotatorComponent {
load() {
try {
const url = this.featureService.has('boost-campaigns') ? 'api/v2/boost/fetch/campaigns' : 'api/v2/boost/feed';
this.feedsService
.setEndpoint('api/v2/boost/fetch/campaigns')
.setEndpoint(url)
.setParams({
rating: this.rating,
})
......
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