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-09-10 02:12:32 +02:00
|
|
|
private loadedAccounts: { [index: string]: AccountInfo } = {};
|
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
|
|
|
|
2018-09-09 22:33:53 +02:00
|
|
|
private currentLoading: number;
|
2018-09-09 07:29:23 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
|
|
|
if (accounts) {
|
2018-09-10 02:12:32 +02:00
|
|
|
this.loadedAccounts = {};
|
|
|
|
this.accounts.length = 0;
|
2018-09-09 22:33:53 +02:00
|
|
|
|
2018-09-10 02:12:32 +02:00
|
|
|
for (let acc of accounts) {
|
2018-09-09 22:33:53 +02:00
|
|
|
const accWrapper = new AccountWrapper();
|
|
|
|
accWrapper.username = `${acc.username}@${acc.instance}`;
|
|
|
|
this.accounts.push(accWrapper);
|
2018-09-10 02:12:32 +02:00
|
|
|
this.loadedAccounts[accWrapper.username] = acc;
|
2018-09-09 22:33:53 +02:00
|
|
|
|
2018-09-09 07:29:23 +02:00
|
|
|
this.accountsService.retrieveAccountDetails(acc)
|
|
|
|
.then((result: Account) => {
|
2018-09-10 02:12:32 +02:00
|
|
|
accWrapper.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-09-10 02:12:32 +02:00
|
|
|
|
|
|
|
onToogleAccountNotify(username: string) {
|
|
|
|
console.warn(`onToogleAccountNotify username ${username}`);
|
2018-03-16 03:43:41 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 02:12:32 +02:00
|
|
|
onOpenMenuNotify(username: string) {
|
|
|
|
console.warn(`onOpenMenuNotify username ${username}`);
|
|
|
|
}
|
|
|
|
|
2018-03-16 03:43:41 +01:00
|
|
|
createNewToot(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-16 01:43:53 +01:00
|
|
|
}
|