Sengi-Windows-MacOS-Linux/src/app/components/left-side-bar/left-side-bar.component.ts

68 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-03-17 17:25:40 +01:00
import { Component, OnInit, OnDestroy } from "@angular/core";
2018-09-09 07:29:23 +02:00
import { Subscription, BehaviorSubject, Observable } from "rxjs";
import { Store } from "@ngxs/store";
2018-03-17 17:25:40 +01:00
2018-09-09 07:29:23 +02:00
import { Account } from "../../services/models/mastodon.interfaces";
2018-03-16 04:48:30 +01:00
import { AccountWrapper } from "../../models/account.models";
2018-09-09 07:29:23 +02:00
import { AccountsService } from "../../services/accounts.service";
import { AccountsStateModel, AccountInfo } from "../../states/accounts.state";
2018-03-16 01:43:53 +01:00
@Component({
2018-03-16 04:48:30 +01:00
selector: "app-left-side-bar",
templateUrl: "./left-side-bar.component.html",
2018-09-08 03:02:16 +02:00
styleUrls: ["./left-side-bar.component.scss"]
2018-03-16 01:43:53 +01:00
})
2018-03-17 17:25:40 +01:00
export class LeftSideBarComponent implements OnInit, OnDestroy {
2018-03-16 03:43:41 +01:00
accounts: AccountWrapper[] = [];
2018-09-09 07:29:23 +02:00
accounts$: Observable<AccountInfo[]>;
2018-03-16 01:43:53 +01:00
2018-03-17 17:25:40 +01:00
private sub: Subscription;
2018-03-16 03:43:41 +01:00
2018-03-17 17:25:40 +01:00
constructor(
2018-09-09 07:29:23 +02:00
private readonly accountsService: AccountsService,
private readonly store: Store) {
2018-03-17 17:25:40 +01:00
2018-09-09 07:29:23 +02:00
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
}
2018-03-17 17:25:40 +01:00
private currentLoading: number;
2018-09-09 07:29:23 +02:00
ngOnInit() {
this.accounts$.subscribe((accounts: AccountInfo[]) => {
console.warn(' this.accounts$.subscribe(');
2018-09-09 07:29:23 +02:00
console.warn(accounts);
2018-03-16 03:43:41 +01:00
2018-09-09 07:29:23 +02:00
if (accounts) {
for (let acc of accounts) {
const accWrapper = new AccountWrapper();
accWrapper.username = `${acc.username}@${acc.instance}`;
this.accounts.push(accWrapper);
2018-09-09 07:29:23 +02:00
this.accountsService.retrieveAccountDetails(acc)
.then((result: Account) => {
console.error(result);
const accounts = this.accounts.filter(x => result.url.includes(acc.username) && result.url.includes(acc.instance));
for (const account of accounts) {
account.avatar = result.avatar;
}
2018-09-09 07:29:23 +02:00
});
}
}
});
2018-03-17 17:25:40 +01:00
}
2018-03-16 03:43:41 +01:00
2018-03-17 17:25:40 +01:00
ngOnDestroy(): void {
this.sub.unsubscribe();
2018-03-16 01:43:53 +01:00
}
2018-03-16 03:43:41 +01:00
addNewAccount(): boolean {
return false;
}
createNewToot(): boolean {
return false;
}
2018-03-16 01:43:53 +01:00
}