import {Component} from '@angular/core';
import {select, Store} from "@ngrx/store";
import {MastodonApiActions} from "../../shared/state/store/actions";
import {selectFollowings, selectLists, selectListsWithAccounts, selectLoading} from "../../shared/state/store/selectors";
import {Observable, tap} from "rxjs";
import {Account, List} from 'projects/mastodon-api/src/public-api';

@Component({
    selector: 'app-sync',
    templateUrl: './sync.component.html',
    styleUrls: ['./sync.component.scss']
})
export class SyncComponent {
    loading$: Observable<boolean>;
    followings$: Observable<ReadonlyArray<Account>>;
    lists$: Observable<ReadonlyArray<List>>;

    constructor(private store: Store) {
        this.followings$ = this.store.pipe(select(selectFollowings))
        this.lists$ = this.store.pipe(select(selectListsWithAccounts));
        this.loading$ = this.store.pipe(select(selectLoading));
    }

    loadListsAndAccounts() {
        this.store.dispatch(MastodonApiActions.loadLists());
        this.store.dispatch(MastodonApiActions.loadFollowings());
    }

}
