2018-09-10 03:55:16 +02:00
|
|
|
import { Component, OnInit, Input } from '@angular/core';
|
2019-01-31 07:01:48 +01:00
|
|
|
import { StreamElement, StreamTypeEnum, AddStream, RemoveAllStreams } from '../../../states/streams.state';
|
2018-09-10 04:33:41 +02:00
|
|
|
import { Store } from '@ngxs/store';
|
2019-01-31 07:01:48 +01:00
|
|
|
import { AccountsStateModel, AccountInfo, RemoveAccount } from '../../../states/accounts.state';
|
2018-09-11 07:54:23 +02:00
|
|
|
import { AccountWrapper } from '../../../models/account.models';
|
2019-01-31 07:01:48 +01:00
|
|
|
import { NavigationService } from '../../../services/navigation.service';
|
2019-02-11 06:56:52 +01:00
|
|
|
import { NotificationService } from '../../../services/notification.service';
|
2018-09-10 03:55:16 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-01-28 06:46:37 +01:00
|
|
|
selector: 'app-manage-account',
|
|
|
|
templateUrl: './manage-account.component.html',
|
|
|
|
styleUrls: ['./manage-account.component.scss']
|
2018-09-10 03:55:16 +02:00
|
|
|
})
|
2018-09-22 06:22:51 +02:00
|
|
|
export class ManageAccountComponent implements OnInit {
|
2019-01-28 06:46:37 +01:00
|
|
|
@Input() account: AccountWrapper;
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-01-28 06:46:37 +01:00
|
|
|
availableStreams: StreamElement[] = [];
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-01-31 07:01:48 +01:00
|
|
|
constructor(
|
|
|
|
private readonly store: Store,
|
2019-02-11 06:56:52 +01:00
|
|
|
private readonly navigationService: NavigationService,
|
|
|
|
private notificationService: NotificationService) { }
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-01-28 06:46:37 +01:00
|
|
|
ngOnInit() {
|
|
|
|
const instance = this.account.info.instance;
|
|
|
|
this.availableStreams.length = 0;
|
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.global, 'Federated Timeline', this.account.info.id, null, null, `federate@${instance}`));
|
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.local, 'Local Timeline', this.account.info.id, null, null, `local@${instance}`));
|
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.personnal, 'Home', this.account.info.id, null, null, `home@${instance}`));
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-01-28 06:46:37 +01:00
|
|
|
addStream(stream: StreamElement): boolean {
|
|
|
|
if (stream) {
|
2019-02-11 06:56:52 +01:00
|
|
|
this.store.dispatch([new AddStream(stream)]).toPromise().then(() => {
|
|
|
|
this.notificationService.notify(`added ${stream.displayableFullName}`, false);
|
|
|
|
});
|
2019-01-28 06:46:37 +01:00
|
|
|
}
|
|
|
|
return false;
|
2018-09-10 04:33:41 +02:00
|
|
|
}
|
2019-01-30 04:33:49 +01:00
|
|
|
|
|
|
|
removeAccount(): boolean {
|
2019-01-31 07:01:48 +01:00
|
|
|
const accountId = this.account.info.id;
|
|
|
|
this.store.dispatch([new RemoveAllStreams(accountId), new RemoveAccount(accountId)]);
|
|
|
|
this.navigationService.closePanel();
|
2019-01-30 04:33:49 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
}
|