Sengi-Windows-MacOS-Linux/src/app/components/floating-column/scheduled-statuses/scheduled-statuses.componen...

55 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { ScheduledStatusService, ScheduledStatusNotification } from '../../../services/scheduled-status.service';
2019-09-07 02:35:42 +02:00
import { ScheduledStatus } from '../../../services/models/mastodon.interfaces';
import { AccountInfo } from '../../../states/accounts.state';
2019-08-25 07:43:47 +02:00
@Component({
selector: 'app-scheduled-statuses',
templateUrl: './scheduled-statuses.component.html',
styleUrls: ['./scheduled-statuses.component.scss']
2019-08-25 07:43:47 +02:00
})
export class ScheduledStatusesComponent implements OnInit, OnDestroy {
private statusSub: Subscription;
2019-09-07 02:35:42 +02:00
scheduledStatuses: ScheduledStatusWrapper[] = [];
2019-08-25 07:43:47 +02:00
constructor(
2019-09-07 22:21:25 +02:00
private readonly scheduledStatusService: ScheduledStatusService) {
}
2019-08-25 07:43:47 +02:00
ngOnInit() {
this.statusSub = this.scheduledStatusService.scheduledStatuses.subscribe((value: ScheduledStatusNotification[]) => {
2019-09-07 02:35:42 +02:00
this.scheduledStatuses.length = 0;
value.forEach(notification => {
notification.statuses.forEach(status => {
let wrapper = new ScheduledStatusWrapper(notification.account, status);
this.scheduledStatuses.push(wrapper);
2019-09-07 22:21:25 +02:00
});
2019-09-07 02:35:42 +02:00
});
2019-09-07 22:21:25 +02:00
this.sortStatuses();
});
}
2019-08-25 07:43:47 +02:00
ngOnDestroy(): void {
if (this.statusSub) this.statusSub.unsubscribe();
}
2019-09-07 22:21:25 +02:00
private sortStatuses() {
this.scheduledStatuses.sort((x, y) => new Date(x.status.scheduled_at).getTime() - new Date(y.status.scheduled_at).getTime());
}
statusRescheduled() {
this.sortStatuses();
}
2019-08-25 07:43:47 +02:00
}
2019-09-07 02:35:42 +02:00
class ScheduledStatusWrapper {
2019-09-07 22:21:25 +02:00
constructor(
2019-09-07 02:35:42 +02:00
public readonly account: AccountInfo,
public status: ScheduledStatus) {
}
}