Added subscriptions in redemption resolver to keep up with changes. Fixed double data entries in some cases (due to resolver changes).
This commit is contained in:
parent
04a50f6db0
commit
c5cdf84f3b
@ -36,7 +36,7 @@ import { HermesClientService } from '../../hermes-client.service';
|
||||
templateUrl: './redemption-list.component.html',
|
||||
styleUrl: './redemption-list.component.scss'
|
||||
})
|
||||
export class RedemptionListComponent implements OnInit, OnDestroy {
|
||||
export class RedemptionListComponent implements OnDestroy {
|
||||
private readonly client = inject(HermesClientService);
|
||||
private readonly redemptionService = inject(RedemptionService);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
@ -58,9 +58,10 @@ export class RedemptionListComponent implements OnInit, OnDestroy {
|
||||
this._twitchRedemptionsDict = Object.assign({}, ...r['twitchRedemptions'].map((t: TwitchRedemption) => ({ [t.id]: t.title })));
|
||||
this._actions = r['redeemableActions'];
|
||||
|
||||
let redemptions = r['redemptions'];
|
||||
let redemptions = [...r['redemptions']];
|
||||
redemptions.sort((a: Redemption, b: Redemption) => this.compare(a, b));
|
||||
this._redemptions = redemptions;
|
||||
});
|
||||
|
||||
let subscription = this.redemptionService.create$?.subscribe(d => {
|
||||
if (d.error || !d.data || d.request.nounce != null && d.request.nounce.startsWith(this.client.session_id)) {
|
||||
@ -103,11 +104,6 @@ export class RedemptionListComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
if (subscription)
|
||||
this._subscriptions.push(subscription);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
@ -10,7 +10,6 @@ export class RedemptionService {
|
||||
private client = inject(HermesClientService);
|
||||
private data: Redemption[] = []
|
||||
create$: Observable<any> | undefined;
|
||||
fetch$: Observable<any> | undefined;
|
||||
update$: Observable<any> | undefined;
|
||||
delete$: Observable<any> | undefined;
|
||||
loaded = false;
|
||||
@ -19,6 +18,18 @@ export class RedemptionService {
|
||||
this.create$ = this.client.filterByRequestType('create_redemption');
|
||||
this.update$ = this.client.filterByRequestType('update_redemption');
|
||||
this.delete$ = this.client.filterByRequestType('delete_redemption');
|
||||
|
||||
this.create$?.subscribe(d => this.data.push(d.data));
|
||||
this.update$?.subscribe(d => {
|
||||
const redemption = this.data.find(r => r.id == d.data.id);
|
||||
if (redemption) {
|
||||
redemption.action_name = d.data.action_name;
|
||||
redemption.redemption_id = d.data.redemption_id;
|
||||
redemption.order = d.data.order;
|
||||
redemption.state = d.data.state;
|
||||
}
|
||||
});
|
||||
this.delete$?.subscribe(d => this.data = this.data.filter(r => r.id != d.request.data.id));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user