From 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Oct 2021 09:44:43 +0200 Subject: Add ability to view my followers --- .../my-follows/my-followers.component.ts | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 client/src/app/+my-library/my-follows/my-followers.component.ts (limited to 'client/src/app/+my-library/my-follows/my-followers.component.ts') diff --git a/client/src/app/+my-library/my-follows/my-followers.component.ts b/client/src/app/+my-library/my-follows/my-followers.component.ts new file mode 100644 index 000000000..a7bbe6d99 --- /dev/null +++ b/client/src/app/+my-library/my-follows/my-followers.component.ts @@ -0,0 +1,76 @@ +import { Subject } from 'rxjs' +import { Component, OnInit } from '@angular/core' +import { ActivatedRoute } from '@angular/router' +import { AuthService, ComponentPagination, Notifier } from '@app/core' +import { UserSubscriptionService } from '@app/shared/shared-user-subscription' +import { ActorFollow } from '@shared/models' + +@Component({ + templateUrl: './my-followers.component.html', + styleUrls: [ './my-followers.component.scss' ] +}) +export class MyFollowersComponent implements OnInit { + follows: ActorFollow[] = [] + + pagination: ComponentPagination = { + currentPage: 1, + itemsPerPage: 10, + totalItems: null + } + + onDataSubject = new Subject() + search: string + + constructor ( + private route: ActivatedRoute, + private auth: AuthService, + private userSubscriptionService: UserSubscriptionService, + private notifier: Notifier + ) {} + + ngOnInit () { + if (this.route.snapshot.queryParams['search']) { + this.search = this.route.snapshot.queryParams['search'] + } + } + + onNearOfBottom () { + // Last page + if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return + + this.pagination.currentPage += 1 + this.loadFollowers() + } + + onSearch (search: string) { + this.search = search + this.loadFollowers(false) + } + + isFollowingAccount (follow: ActorFollow) { + return follow.following.name === this.getUsername() + } + + private loadFollowers (more = true) { + this.userSubscriptionService.listFollowers({ + pagination: this.pagination, + nameWithHost: this.getUsername(), + search: this.search + }).subscribe({ + next: res => { + this.follows = more + ? this.follows.concat(res.data) + : res.data + this.pagination.totalItems = res.total + + this.onDataSubject.next(res.data) + }, + + error: err => this.notifier.error(err.message) + }) + } + + private getUsername () { + return this.auth.getUser().username + } +} -- cgit v1.2.3