2018-09-10 03:55:16 +02:00
|
|
|
import { Component, OnInit, Input } from '@angular/core';
|
2018-09-10 04:33:41 +02:00
|
|
|
import { Store } from '@ngxs/store';
|
2019-03-20 03:07:42 +01:00
|
|
|
import { faAt, faUserPlus } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { faBell, faEnvelope, faUser, faStar } from "@fortawesome/free-regular-svg-icons";
|
2019-03-19 05:21:00 +01:00
|
|
|
|
|
|
|
import { StreamElement, StreamTypeEnum, AddStream, RemoveAllStreams } from '../../../states/streams.state';
|
|
|
|
import { 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-03-19 05:21:00 +01:00
|
|
|
faAt = faAt;
|
|
|
|
faBell = faBell;
|
|
|
|
faEnvelope = faEnvelope;
|
|
|
|
faUser = faUser;
|
2019-03-20 03:07:42 +01:00
|
|
|
faStar = faStar;
|
|
|
|
faUserPlus = faUserPlus;
|
2019-03-19 05:21:00 +01:00
|
|
|
|
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;
|
2019-02-24 04:40:22 +01:00
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.global, 'Federated Timeline', this.account.info.id, null, null, instance));
|
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.local, 'Local Timeline', this.account.info.id, null, null, instance));
|
|
|
|
this.availableStreams.push(new StreamElement(StreamTypeEnum.personnal, 'Home', this.account.info.id, null, null, instance));
|
2019-01-28 06:46:37 +01:00
|
|
|
}
|
2018-09-10 03:55:16 +02:00
|
|
|
|
2019-01-28 06:46:37 +01:00
|
|
|
addStream(stream: StreamElement): boolean {
|
|
|
|
if (stream) {
|
2019-02-12 05:41:21 +01:00
|
|
|
this.store.dispatch([new AddStream(stream)]).toPromise()
|
|
|
|
.then(() => {
|
2019-02-24 04:40:22 +01:00
|
|
|
this.notificationService.notify(`stream added`, false);
|
2019-02-12 05:41:21 +01:00
|
|
|
});
|
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
|
|
|
}
|